Skip to content

Commit

Permalink
add test for pulling after shallow clone
Browse files Browse the repository at this point in the history
  • Loading branch information
dhoizner committed Nov 26, 2023
1 parent 45307e0 commit b74ae19
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,9 @@ func isFastForward(s storer.EncodedObjectStorer, old, new plumbing.Hash, earlies

found := false
// stop iterating at the earlist shallow commit, ignoring its parents
// note: when pull depth is smaller than the number of new changes on the remote, this fails due to missing parents.
// as far as i can tell, without the commits in-between the shallow pull and the earliest shallow, there's no
// real way of telling whether it will be a fast-forward merge.
iter := object.NewCommitPreorderIter(c, nil, parentsToIgnore)
err = iter.ForEach(func(c *object.Commit) error {
if c.Hash != old {
Expand Down
36 changes: 36 additions & 0 deletions worktree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,42 @@ func (s *WorktreeSuite) TestPullDepth(c *C) {
c.Assert(err, Equals, nil)
}

func (s *WorktreeSuite) TestPullAfterShallowClone(c *C) {
tempDir, clean := s.TemporalDir()
defer clean()
remoteURL := filepath.Join(tempDir, "remote")
repoDir := filepath.Join(tempDir, "repo")

remote, err := PlainInit(remoteURL, false)
c.Assert(err, IsNil)
c.Assert(remote, NotNil)

_ = CommitNewFile(c, remote, "File1")
_ = CommitNewFile(c, remote, "File2")

repo, err := PlainClone(repoDir, false, &CloneOptions{
URL: remoteURL,
Depth: 1,
Tags: NoTags,
SingleBranch: true,
ReferenceName: "master",
})
c.Assert(err, IsNil)

_ = CommitNewFile(c, remote, "File3")
_ = CommitNewFile(c, remote, "File4")

w, err := repo.Worktree()
c.Assert(err, IsNil)

err = w.Pull(&PullOptions{
RemoteName: DefaultRemoteName,
SingleBranch: true,
ReferenceName: plumbing.NewBranchReferenceName("master"),
})
c.Assert(err, IsNil)
}

func (s *WorktreeSuite) TestCheckout(c *C) {
fs := memfs.New()
w := &Worktree{
Expand Down

0 comments on commit b74ae19

Please sign in to comment.