MCPcopy Create free account
hub / github.com/BillHuang2001/evogit / add_temp_worktree

Function add_temp_worktree

python-impl/evogit/utils/git.py:531–550  ·  view source on GitHub ↗

checkout the branch in a new worktree and return the path of the worktree.

(config: EvoGitConfig, branch: str)

Source from the content-addressed store, hash-verified

529
530
531def 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
553def remove_temp_worktree(config: EvoGitConfig, worktree: str) -> None:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected