diff --git a/codeflash/cli_cmds/cli.py b/codeflash/cli_cmds/cli.py index 933274c19..27857806f 100644 --- a/codeflash/cli_cmds/cli.py +++ b/codeflash/cli_cmds/cli.py @@ -11,6 +11,7 @@ from codeflash.code_utils import env_utils from codeflash.code_utils.code_utils import exit_with_message from codeflash.code_utils.config_parser import parse_config_file +from codeflash.code_utils.git_utils import git_root_dir from codeflash.lsp.helpers import is_LSP_enabled from codeflash.version import __version__ as version @@ -222,18 +223,20 @@ def process_pyproject_config(args: Namespace) -> Namespace: args.module_root = Path(args.module_root).resolve() # If module-root is "." then all imports are relatives to it. # in this case, the ".." becomes outside project scope, causing issues with un-importable paths - args.project_root = project_root_from_module_root(args.module_root, pyproject_file_path) + args.project_root = project_root_from_module_root(args.module_root, pyproject_file_path, args.worktree) args.tests_root = Path(args.tests_root).resolve() if args.benchmarks_root: args.benchmarks_root = Path(args.benchmarks_root).resolve() - args.test_project_root = project_root_from_module_root(args.tests_root, pyproject_file_path) + args.test_project_root = project_root_from_module_root(args.tests_root, pyproject_file_path, args.worktree) if is_LSP_enabled(): args.all = None return args return handle_optimize_all_arg_parsing(args) -def project_root_from_module_root(module_root: Path, pyproject_file_path: Path) -> Path: +def project_root_from_module_root(module_root: Path, pyproject_file_path: Path, in_worktree: bool = False) -> Path: # noqa: FBT001, FBT002 + if in_worktree: + return git_root_dir() if pyproject_file_path.parent == module_root: return module_root return module_root.parent.resolve()