diff options
author | Ayman Bagabas <ayman.bagabas@gmail.com> | 2023-12-12 12:26:54 -0500 |
---|---|---|
committer | Ayman Bagabas <ayman.bagabas@gmail.com> | 2023-12-12 13:27:51 -0500 |
commit | 1e2b0d67ae859dc3c81fc4455290287235395d09 (patch) | |
tree | c063cd037870ed8abde16fd411ea266e6ef9acc0 /worktree_test.go | |
parent | 952f1baf5e6ffc9e2e143821368944b40fa0bdbf (diff) | |
download | go-git-1e2b0d67ae859dc3c81fc4455290287235395d09.tar.gz |
git: worktree checkout tag hash id (#959)
Allow checking out a worktree using a tag hash id.
Fixes: https://github.com/go-git/go-git/issues/959
Supersedes: https://github.com/go-git/go-git/pull/964
Diffstat (limited to 'worktree_test.go')
-rw-r--r-- | worktree_test.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/worktree_test.go b/worktree_test.go index 50ff189..5759ec4 100644 --- a/worktree_test.go +++ b/worktree_test.go @@ -886,6 +886,41 @@ func (s *WorktreeSuite) TestCheckoutTag(c *C) { c.Assert(head.Name().String(), Equals, "HEAD") } +func (s *WorktreeSuite) TestCheckoutTagHash(c *C) { + f := fixtures.ByTag("tags").One() + r := s.NewRepositoryWithEmptyWorktree(f) + w, err := r.Worktree() + c.Assert(err, IsNil) + + for _, hash := range []string{ + "b742a2a9fa0afcfa9a6fad080980fbc26b007c69", // annotated tag + "ad7897c0fb8e7d9a9ba41fa66072cf06095a6cfc", // commit tag + "f7b877701fbf855b44c0a9e86f3fdce2c298b07f", // lightweight tag + } { + err = w.Checkout(&CheckoutOptions{ + Hash: plumbing.NewHash(hash), + }) + c.Assert(err, IsNil) + head, err := w.r.Head() + c.Assert(err, IsNil) + c.Assert(head.Name().String(), Equals, "HEAD") + + status, err := w.Status() + c.Assert(err, IsNil) + c.Assert(status.IsClean(), Equals, true) + } + + for _, hash := range []string{ + "fe6cb94756faa81e5ed9240f9191b833db5f40ae", // blob tag + "152175bf7e5580299fa1f0ba41ef6474cc043b70", // tree tag + } { + err = w.Checkout(&CheckoutOptions{ + Hash: plumbing.NewHash(hash), + }) + c.Assert(err, NotNil) + } +} + func (s *WorktreeSuite) TestCheckoutBisect(c *C) { if testing.Short() { c.Skip("skipping test in short mode.") |