aboutsummaryrefslogtreecommitdiffstats
path: root/submodule.go
diff options
context:
space:
mode:
Diffstat (limited to 'submodule.go')
-rw-r--r--submodule.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/submodule.go b/submodule.go
index b6bef46..16e946d 100644
--- a/submodule.go
+++ b/submodule.go
@@ -254,6 +254,24 @@ func (s *Submodule) fetchAndCheckout(
return err
}
+ // Handle a case when submodule refers to an orphaned commit that's still reachable
+ // through Git server using a special protocol capability[1].
+ //
+ // [1]: https://git-scm.com/docs/protocol-capabilities#_allow_reachable_sha1_in_want
+ if !o.NoFetch {
+ if _, err := w.r.Object(plumbing.AnyObject, hash); err != nil {
+ refSpec := config.RefSpec("+" + hash.String() + ":" + hash.String())
+
+ err := r.FetchContext(ctx, &FetchOptions{
+ Auth: o.Auth,
+ RefSpecs: []config.RefSpec{refSpec},
+ })
+ if err != nil && err != NoErrAlreadyUpToDate && err != ErrExactSHA1NotSupported {
+ return err
+ }
+ }
+ }
+
if err := w.Checkout(&CheckoutOptions{Hash: hash}); err != nil {
return err
}