diff options
author | Peter Jones <pjones@redhat.com> | 2017-06-26 14:54:28 -0400 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2017-07-01 13:59:17 +0200 |
commit | aec58a9d386d4199374139cd1fc466826ac3d2cf (patch) | |
tree | 81e24d83a4e95410fd63b986dc420f8d488fce66 /git/test/test_repo.py | |
parent | 4bd708d41090fbe00acb41246eb22fa8b5632967 (diff) | |
download | gitpython-aec58a9d386d4199374139cd1fc466826ac3d2cf.tar.gz |
Repo: handle worktrees better
This makes Repo("foo") work when foo/.git is a file of the form created
by "git worktree add", i.e. it's a text file that says:
gitdir: /home/me/project/.git/worktrees/bar
and where /home/me/project/.git/ is the nominal gitdir, but
/home/me/project/.git/worktrees/bar has this worktree's HEAD etc and a
"gitdir" file that contains the path of foo/.git .
Signed-off-by: Peter Jones <pjones@redhat.com>
Diffstat (limited to 'git/test/test_repo.py')
-rw-r--r-- | git/test/test_repo.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/git/test/test_repo.py b/git/test/test_repo.py index 86019b73..a6be4e66 100644 --- a/git/test/test_repo.py +++ b/git/test/test_repo.py @@ -22,6 +22,7 @@ from git import ( NoSuchPathError, Head, Commit, + Object, Tree, IndexFile, Git, @@ -911,22 +912,28 @@ class TestRepo(TestBase): self.assertRaises(GitCommandError, repo.is_ancestor, i, j) @with_rw_directory - def test_work_tree_unsupported(self, rw_dir): + def test_git_work_tree_dotgit(self, rw_dir): + """Check that we find .git as a worktree file and find the worktree + based on it.""" git = Git(rw_dir) if git.version_info[:3] < (2, 5, 1): raise SkipTest("worktree feature unsupported") rw_master = self.rorepo.clone(join_path_native(rw_dir, 'master_repo')) - rw_master.git.checkout('HEAD~10') + branch = rw_master.create_head('aaaaaaaa') worktree_path = join_path_native(rw_dir, 'worktree_repo') if Git.is_cygwin(): worktree_path = cygpath(worktree_path) - try: - rw_master.git.worktree('add', worktree_path, 'master') - except Exception as ex: - raise AssertionError(ex, "It's ok if TC not running from `master`.") + rw_master.git.worktree('add', worktree_path, branch.name) + + # this ensures that we can read the repo's gitdir correctly + repo = Repo(worktree_path) + self.assertIsInstance(repo, Repo) - self.failUnlessRaises(InvalidGitRepositoryError, Repo, worktree_path) + # this ensures we're able to actually read the refs in the tree, which + # means we can read commondir correctly. + commit = repo.head.commit + self.assertIsInstance(commit, Object) @with_rw_directory def test_git_work_tree_env(self, rw_dir): |