checkout the branch in a new worktree and return the path of the worktree.
(config: EvoGitConfig, branch: str)
| 529 | |
| 530 | |
| 531 | def add_temp_worktree(config: EvoGitConfig, branch: str) -> str: |
| 532 | """checkout the branch in a new worktree and return the path of the worktree.""" |
| 533 | # make a temporary directory if not exists |
| 534 | worktree_dir = os.path.join(config.git_dir, ".phylox_evaluate") |
| 535 | if not os.path.exists(worktree_dir): |
| 536 | # in case we have multiple instances running at the same time |
| 537 | try: |
| 538 | os.mkdir(worktree_dir) |
| 539 | except FileExistsError: |
| 540 | pass |
| 541 | |
| 542 | worktree = tempfile.mkdtemp(prefix=f"{branch}_", dir=worktree_dir) |
| 543 | subprocess.run( |
| 544 | ["git", "worktree", "add", "--detach", "-q", worktree, branch], |
| 545 | cwd=config.git_dir, |
| 546 | check=True, |
| 547 | stdout=subprocess.DEVNULL, |
| 548 | stderr=subprocess.DEVNULL, |
| 549 | ) |
| 550 | return worktree |
| 551 | |
| 552 | |
| 553 | def remove_temp_worktree(config: EvoGitConfig, worktree: str) -> None: |
nothing calls this directly
no outgoing calls
no test coverage detected