(testrepo: Repository)
| 863 | |
| 864 | |
| 865 | def 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 | |
| 907 | def test_worktree_aspath(testrepo: Repository) -> None: |
nothing calls this directly
no test coverage detected
searching dependent graphs…