MCPcopy Create free account
hub / github.com/libgit2/pygit2 / test_worktree_custom_ref

Function test_worktree_custom_ref

test/test_repository.py:917–949  ·  view source on GitHub ↗
(testrepo: Repository)

Source from the content-addressed store, hash-verified

915
916
917def test_worktree_custom_ref(testrepo: Repository) -> None:
918 worktree_name = 'foo'
919 worktree_dir = Path(tempfile.mkdtemp())
920 branch_name = 'version1'
921
922 # New branch based on head
923 tip = testrepo.revparse_single('HEAD')
924 assert isinstance(tip, Commit)
925 worktree_ref = testrepo.branches.create(branch_name, tip)
926 # Delete temp path so that it's not present when we attempt to add the
927 # worktree later
928 worktree_dir.rmdir()
929
930 # Add a worktree for the given ref
931 worktree = testrepo.add_worktree(worktree_name, str(worktree_dir), worktree_ref)
932 # We should have one worktree now
933 assert testrepo.list_worktrees() == [worktree_name]
934 # We should not have a branch of the same name
935 assert worktree_name not in testrepo.listall_branches()
936
937 # The given ref is checked out in the "worktree repository"
938 assert worktree_ref.is_checked_out()
939
940 # Remove the worktree dir and prune the worktree
941 shutil.rmtree(worktree_dir)
942 worktree.prune(True)
943 assert testrepo.list_worktrees() == []
944
945 # The ref is no longer checked out
946 assert worktree_ref.is_checked_out() is False
947
948 # The branch still exists
949 assert branch_name in testrepo.branches
950
951
952def test_open_extended(tmp_path: Path) -> None:

Callers

nothing calls this directly

Calls 2

pruneMethod · 0.80
createMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…