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

Commit 8c61d43

Browse files
committed
Fix edge case when fetching remotes with unrelated incomplete 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 <[email protected]>
1 parent 7bdcd80 commit 8c61d43

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

remote.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,11 @@ func getHaves(
623623
}
624624

625625
err = getHavesFromRef(ref, remoteRefs, s, haves)
626-
if err != nil {
626+
627+
// Take care of the edge case where iterating using Preorder over
628+
// commits produces an `object not found` error, if using a shallow
629+
// clone with incomplete history.
630+
if err != nil && err != plumbing.ErrObjectNotFound {
627631
return nil, err
628632
}
629633
}

remote_test.go

+32
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package git
33
import (
44
"bytes"
55
"context"
6+
"fmt"
67
"io"
78
"io/ioutil"
89
"os"
@@ -55,6 +56,37 @@ func (s *RemoteSuite) TestFetchInvalidFetchOptions(c *C) {
5556
c.Assert(err, Equals, config.ErrRefSpecMalformedSeparator)
5657
}
5758

59+
func (s *RemoteSuite) TestFetchUnrelated(c *C) {
60+
fmt.Println(fixtures.RootFolder)
61+
mem := memory.NewStorage()
62+
r1 := newRemote(mem, &config.RemoteConfig{
63+
URLs: []string{s.GetBasicLocalRepositoryURL()},
64+
})
65+
r2 := newRemote(mem, &config.RemoteConfig{
66+
URLs: []string{s.GetLocalRepositoryURL(fixtures.ByTag("tags").One())},
67+
})
68+
69+
// Fetch both repos into the same storage but under different remote names.
70+
s.testFetch(c, r1, &FetchOptions{
71+
RefSpecs: []config.RefSpec{
72+
config.RefSpec("+refs/heads/master:refs/remotes/r1/master"),
73+
},
74+
Depth: 1,
75+
}, []*plumbing.Reference{
76+
plumbing.NewReferenceFromStrings("refs/remotes/r1/master", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5"),
77+
})
78+
s.testFetch(c, r2, &FetchOptions{
79+
RefSpecs: []config.RefSpec{
80+
config.RefSpec("+refs/heads/master:refs/remotes/r2/master"),
81+
},
82+
Depth: 1,
83+
}, []*plumbing.Reference{
84+
plumbing.NewReferenceFromStrings("refs/remotes/r1/master", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5"),
85+
plumbing.NewReferenceFromStrings("refs/remotes/r2/master", "f7b877701fbf855b44c0a9e86f3fdce2c298b07f"),
86+
})
87+
88+
}
89+
5890
func (s *RemoteSuite) TestFetchWildcard(c *C) {
5991
r := newRemote(memory.NewStorage(), &config.RemoteConfig{
6092
URLs: []string{s.GetBasicLocalRepositoryURL()},

0 commit comments

Comments
 (0)