Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix edge case when fetching remotes with unrelated incomplete history… #1

Merged
merged 1 commit into from
Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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