Skip to content
This repository has been archived by the owner on Sep 11, 2020. It is now read-only.

Commit

Permalink
Fix edge case when fetching remotes with unrelated incomplete history.
Browse files Browse the repository at this point in the history
…Fixes #1151

In getHaves, allow the getHavesRef to fail with Object Not found when
iterating over incomplete history, and don't treat it as a fatal error.

Signed-off-by: Oleg Utkin <oleg.utkin@nonlogical.io>
  • Loading branch information
NonLogicalDev committed May 17, 2019
1 parent 7bdcd80 commit 8c61d43
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
6 changes: 5 additions & 1 deletion remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,11 @@ func getHaves(
}

err = getHavesFromRef(ref, remoteRefs, s, haves)
if err != nil {

// Take care of the edge case where iterating using Preorder over
// commits produces an `object not found` error, if using a shallow
// clone with incomplete history.
if err != nil && err != plumbing.ErrObjectNotFound {
return nil, err
}
}
Expand Down
32 changes: 32 additions & 0 deletions remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package git
import (
"bytes"
"context"
"fmt"
"io"
"io/ioutil"
"os"
Expand Down Expand Up @@ -55,6 +56,37 @@ func (s *RemoteSuite) TestFetchInvalidFetchOptions(c *C) {
c.Assert(err, Equals, config.ErrRefSpecMalformedSeparator)
}

func (s *RemoteSuite) TestFetchUnrelated(c *C) {
fmt.Println(fixtures.RootFolder)
mem := memory.NewStorage()
r1 := newRemote(mem, &config.RemoteConfig{
URLs: []string{s.GetBasicLocalRepositoryURL()},
})
r2 := newRemote(mem, &config.RemoteConfig{
URLs: []string{s.GetLocalRepositoryURL(fixtures.ByTag("tags").One())},
})

// Fetch both repos into the same storage but under different remote names.
s.testFetch(c, r1, &FetchOptions{
RefSpecs: []config.RefSpec{
config.RefSpec("+refs/heads/master:refs/remotes/r1/master"),
},
Depth: 1,
}, []*plumbing.Reference{
plumbing.NewReferenceFromStrings("refs/remotes/r1/master", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5"),
})
s.testFetch(c, r2, &FetchOptions{
RefSpecs: []config.RefSpec{
config.RefSpec("+refs/heads/master:refs/remotes/r2/master"),
},
Depth: 1,
}, []*plumbing.Reference{
plumbing.NewReferenceFromStrings("refs/remotes/r1/master", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5"),
plumbing.NewReferenceFromStrings("refs/remotes/r2/master", "f7b877701fbf855b44c0a9e86f3fdce2c298b07f"),
})

}

func (s *RemoteSuite) TestFetchWildcard(c *C) {
r := newRemote(memory.NewStorage(), &config.RemoteConfig{
URLs: []string{s.GetBasicLocalRepositoryURL()},
Expand Down

0 comments on commit 8c61d43

Please sign in to comment.