|
15 | 15 | from codeflash.code_utils import env_utils |
16 | 16 | from codeflash.code_utils.code_utils import cleanup_paths, get_run_tmp_file |
17 | 17 | from codeflash.code_utils.env_utils import get_pr_number, is_pr_draft |
18 | | -from codeflash.code_utils.git_utils import check_running_in_git_repo |
| 18 | +from codeflash.code_utils.git_utils import check_running_in_git_repo, git_root_dir |
19 | 19 | from codeflash.code_utils.git_worktree_utils import ( |
20 | 20 | create_detached_worktree, |
21 | 21 | create_diff_patch_from_worktree, |
@@ -447,35 +447,52 @@ def worktree_mode(self) -> None: |
447 | 447 | Path(self.args.tests_root).mkdir(parents=True, exist_ok=True) |
448 | 448 |
|
449 | 449 | def mutate_args_for_worktree_mode(self, worktree_dir: Path) -> None: |
450 | | - saved_args = copy.deepcopy(self.args) |
451 | | - saved_test_cfg = copy.deepcopy(self.test_cfg) |
452 | | - self.original_args_and_test_cfg = (saved_args, saved_test_cfg) |
453 | | - |
454 | | - project_root = self.args.project_root |
455 | | - module_root = self.args.module_root |
456 | | - relative_module_root = module_root.relative_to(project_root) |
457 | | - relative_optimized_file = self.args.file.relative_to(project_root) if self.args.file else None |
458 | | - relative_tests_root = self.test_cfg.tests_root.relative_to(project_root) |
459 | | - relative_benchmarks_root = ( |
460 | | - self.args.benchmarks_root.relative_to(project_root) if self.args.benchmarks_root else None |
| 450 | + original_args = copy.deepcopy(self.args) |
| 451 | + original_test_cfg = copy.deepcopy(self.test_cfg) |
| 452 | + self.original_args_and_test_cfg = (original_args, original_test_cfg) |
| 453 | + |
| 454 | + original_module_root = original_args.module_root |
| 455 | + original_git_root = git_root_dir().as_posix() |
| 456 | + |
| 457 | + # mutate project_root |
| 458 | + relative_project_root = original_args.project_root.relative_to(original_git_root).as_posix() |
| 459 | + # this will be the same as the original project root but in the worktree |
| 460 | + new_project_root = worktree_dir / relative_project_root |
| 461 | + self.args.project_root = new_project_root |
| 462 | + self.test_cfg.project_root_path = new_project_root |
| 463 | + |
| 464 | + # mutate module_root |
| 465 | + relative_module_root = original_module_root.relative_to(original_git_root).as_posix() |
| 466 | + self.args.module_root = worktree_dir / relative_module_root |
| 467 | + |
| 468 | + # mute target file |
| 469 | + relative_optimized_file = ( |
| 470 | + original_args.file.relative_to(original_git_root).as_posix() if original_args.file else None |
461 | 471 | ) |
| 472 | + if relative_optimized_file is not None: |
| 473 | + self.args.file = worktree_dir / relative_optimized_file |
462 | 474 |
|
463 | | - self.args.module_root = worktree_dir / relative_module_root |
464 | | - self.args.project_root = worktree_dir |
465 | | - self.args.test_project_root = worktree_dir |
466 | | - self.args.tests_root = worktree_dir / relative_tests_root |
467 | | - if relative_benchmarks_root: |
468 | | - self.args.benchmarks_root = worktree_dir / relative_benchmarks_root |
| 475 | + # mutate tests root |
| 476 | + relative_tests_root = original_test_cfg.tests_root.relative_to(original_git_root).as_posix() |
| 477 | + new_tests_root = worktree_dir / relative_tests_root |
| 478 | + self.args.tests_root = new_tests_root |
| 479 | + self.test_cfg.tests_root = new_tests_root |
469 | 480 |
|
470 | | - self.test_cfg.project_root_path = worktree_dir |
471 | | - self.test_cfg.tests_project_rootdir = worktree_dir |
472 | | - self.test_cfg.tests_root = worktree_dir / relative_tests_root |
| 481 | + # mutate tests project root |
| 482 | + relative_tests_project_root = original_args.test_project_root.relative_to(original_git_root).as_posix() |
| 483 | + self.args.test_project_root = worktree_dir / relative_tests_project_root |
| 484 | + self.test_cfg.tests_project_rootdir = worktree_dir / relative_tests_project_root |
| 485 | + |
| 486 | + # mutate benchmarks root |
| 487 | + relative_benchmarks_root = ( |
| 488 | + original_args.benchmarks_root.relative_to(original_git_root).as_posix() |
| 489 | + if original_args.benchmarks_root |
| 490 | + else None |
| 491 | + ) |
473 | 492 | if relative_benchmarks_root: |
| 493 | + self.args.benchmarks_root = worktree_dir / relative_benchmarks_root |
474 | 494 | self.test_cfg.benchmark_tests_root = worktree_dir / relative_benchmarks_root |
475 | 495 |
|
476 | | - if relative_optimized_file is not None: |
477 | | - self.args.file = worktree_dir / relative_optimized_file |
478 | | - |
479 | 496 |
|
480 | 497 | def run_with_args(args: Namespace) -> None: |
481 | 498 | optimizer = None |
|
0 commit comments