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

Function test_worktree

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

Source from the content-addressed store, hash-verified

863
864
865def test_worktree(testrepo: Repository) -> None:
866 worktree_name = 'foo'
867 worktree_dir = Path(tempfile.mkdtemp())
868 # Delete temp path so that it's not present when we attempt to add the
869 # worktree later
870 worktree_dir.rmdir()
871
872 def _check_worktree(worktree: Worktree) -> None:
873 # Confirm the name attribute matches the specified name
874 assert worktree.name == worktree_name
875 # Confirm the path attribute points to the correct path
876 assert Path(worktree.path).resolve() == worktree_dir.resolve()
877 # The "gitdir" in a worktree should be a file with a reference to
878 # the actual gitdir. Let's make sure that the path exists and is a
879 # file.
880 assert (worktree_dir / '.git').is_file()
881
882 # We should have zero worktrees
883 assert testrepo.list_worktrees() == []
884 # Add a worktree
885 worktree = testrepo.add_worktree(worktree_name, str(worktree_dir))
886 # Check that the worktree was added properly
887 _check_worktree(worktree)
888 # We should have one worktree now
889 assert testrepo.list_worktrees() == [worktree_name]
890 # We should also have a branch of the same name
891 assert worktree_name in testrepo.listall_branches()
892 # Test that lookup_worktree() returns a properly-instantiated
893 # pygit2._Worktree object
894 _check_worktree(testrepo.lookup_worktree(worktree_name))
895 # Remove the worktree dir
896 shutil.rmtree(worktree_dir)
897 # Prune the worktree. For some reason, libgit2 treats a worktree as
898 # valid unless both the worktree directory and data dir under
899 # $GIT_DIR/worktrees are gone. This doesn't make much sense since the
900 # normal usage involves removing the worktree directory and then
901 # pruning. So, for now we have to force the prune. This may be
902 # something to take up with libgit2.
903 worktree.prune(True)
904 assert testrepo.list_worktrees() == []
905
906
907def test_worktree_aspath(testrepo: Repository) -> None:

Callers

nothing calls this directly

Calls 2

_check_worktreeFunction · 0.85
pruneMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…