aboutsummaryrefslogtreecommitdiffstats
path: root/submodule.go
diff options
context:
space:
mode:
authorNikolay Edigaryev <edigaryev@gmail.com>2021-04-07 00:53:25 +0300
committerGitHub <noreply@github.com>2021-04-06 23:53:25 +0200
commit2f7c4ae04d62705c98db0cf900410b5e6f6d5021 (patch)
tree1dfe55f4a93fe810656d13d7046a79319c725572 /submodule.go
parentbd662b091fad176e225b39e7f05b73ecba37cd72 (diff)
downloadgo-git-2f7c4ae04d62705c98db0cf900410b5e6f6d5021.tar.gz
Fetch submodules pointing to orphaned but still reachable commits (#284)
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
}