( ctx context.Context, r *Repository, o *SubmoduleUpdateOptions, hash plumbing.Hash, )
| 240 | } |
| 241 | |
| 242 | func (s *Submodule) fetchAndCheckout( |
| 243 | ctx context.Context, r *Repository, o *SubmoduleUpdateOptions, hash plumbing.Hash, |
| 244 | ) error { |
| 245 | if !o.NoFetch { |
| 246 | err := r.FetchContext(ctx, &FetchOptions{Auth: o.Auth, Depth: o.Depth}) |
| 247 | if err != nil && err != NoErrAlreadyUpToDate { |
| 248 | return err |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | w, err := r.Worktree() |
| 253 | if err != nil { |
| 254 | return err |
| 255 | } |
| 256 | |
| 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 | Depth: o.Depth, |
| 269 | }) |
| 270 | if err != nil && err != NoErrAlreadyUpToDate && err != ErrExactSHA1NotSupported { |
| 271 | return err |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | if err := w.Checkout(&CheckoutOptions{Hash: hash}); err != nil { |
| 277 | return err |
| 278 | } |
| 279 | |
| 280 | head := plumbing.NewHashReference(plumbing.HEAD, hash) |
| 281 | return r.Storer.SetReference(head) |
| 282 | } |
| 283 | |
| 284 | // Submodules list of several submodules from the same repository. |
| 285 | type Submodules []*Submodule |
no test coverage detected