( ctx context.Context, r *Repository, o *SubmoduleUpdateOptions, hash plumbing.Hash, )
| 306 | } |
| 307 | |
| 308 | func (s *Submodule) fetchAndCheckout( |
| 309 | ctx context.Context, r *Repository, o *SubmoduleUpdateOptions, hash plumbing.Hash, |
| 310 | ) error { |
| 311 | if !o.NoFetch { |
| 312 | err := r.FetchContext(ctx, &FetchOptions{Auth: o.Auth, Depth: o.Depth}) |
| 313 | if err != nil && err != NoErrAlreadyUpToDate { |
| 314 | return err |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | w, err := r.Worktree() |
| 319 | if err != nil { |
| 320 | return err |
| 321 | } |
| 322 | |
| 323 | // Handle a case when submodule refers to an orphaned commit that's still reachable |
| 324 | // through Git server using a special protocol capability[1]. |
| 325 | // |
| 326 | // [1]: https://git-scm.com/docs/protocol-capabilities#_allow_reachable_sha1_in_want |
| 327 | if !o.NoFetch { |
| 328 | if _, err := w.r.Object(plumbing.AnyObject, hash); err != nil { |
| 329 | refSpec := config.RefSpec("+" + hash.String() + ":" + hash.String()) |
| 330 | |
| 331 | err := r.FetchContext(ctx, &FetchOptions{ |
| 332 | Auth: o.Auth, |
| 333 | RefSpecs: []config.RefSpec{refSpec}, |
| 334 | Depth: o.Depth, |
| 335 | }) |
| 336 | if err != nil && err != NoErrAlreadyUpToDate && err != ErrExactSHA1NotSupported { |
| 337 | return err |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | if err := w.Checkout(&CheckoutOptions{Hash: hash}); err != nil { |
| 343 | return err |
| 344 | } |
| 345 | |
| 346 | head := plumbing.NewHashReference(plumbing.HEAD, hash) |
| 347 | return r.Storer.SetReference(head) |
| 348 | } |
| 349 | |
| 350 | // Submodules list of several submodules from the same repository. |
| 351 | type Submodules []*Submodule |
no test coverage detected