Skip to content

Commit 2f7c4ae

Browse files
authored
Fetch submodules pointing to orphaned but still reachable commits (go-git#284)
1 parent bd662b0 commit 2f7c4ae

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

submodule.go

+18
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,24 @@ func (s *Submodule) fetchAndCheckout(
254254
return err
255255
}
256256

257+
// Handle a case when submodule refers to an orphaned commit that's still reachable
258+
// through Git server using a special protocol capability[1].
259+
//
260+
// [1]: https://git-scm.com/docs/protocol-capabilities#_allow_reachable_sha1_in_want
261+
if !o.NoFetch {
262+
if _, err := w.r.Object(plumbing.AnyObject, hash); err != nil {
263+
refSpec := config.RefSpec("+" + hash.String() + ":" + hash.String())
264+
265+
err := r.FetchContext(ctx, &FetchOptions{
266+
Auth: o.Auth,
267+
RefSpecs: []config.RefSpec{refSpec},
268+
})
269+
if err != nil && err != NoErrAlreadyUpToDate && err != ErrExactSHA1NotSupported {
270+
return err
271+
}
272+
}
273+
}
274+
257275
if err := w.Checkout(&CheckoutOptions{Hash: hash}); err != nil {
258276
return err
259277
}

0 commit comments

Comments
 (0)