PullContext incorporates changes from a remote repository into the current branch. Returns nil if the operation is successful, NoErrAlreadyUpToDate if there are no changes to be fetched, or an error. Pull only supports merges where the can be resolved as a fast-forward. The provided Context must b
(ctx context.Context, o *PullOptions)
| 62 | // operation is complete, an error is returned. The context only affects the |
| 63 | // transport operations. |
| 64 | func (w *Worktree) PullContext(ctx context.Context, o *PullOptions) error { |
| 65 | if err := o.Validate(); err != nil { |
| 66 | return err |
| 67 | } |
| 68 | |
| 69 | remote, err := w.r.Remote(o.RemoteName) |
| 70 | if err != nil { |
| 71 | return err |
| 72 | } |
| 73 | |
| 74 | fetchHead, err := remote.fetch(ctx, &FetchOptions{ |
| 75 | RemoteName: o.RemoteName, |
| 76 | RemoteURL: o.RemoteURL, |
| 77 | Depth: o.Depth, |
| 78 | Auth: o.Auth, |
| 79 | Progress: o.Progress, |
| 80 | Force: o.Force, |
| 81 | InsecureSkipTLS: o.InsecureSkipTLS, |
| 82 | ClientCert: o.ClientCert, |
| 83 | ClientKey: o.ClientKey, |
| 84 | CABundle: o.CABundle, |
| 85 | ProxyOptions: o.ProxyOptions, |
| 86 | }) |
| 87 | |
| 88 | updated := true |
| 89 | if err == NoErrAlreadyUpToDate { |
| 90 | updated = false |
| 91 | } else if err != nil { |
| 92 | return err |
| 93 | } |
| 94 | |
| 95 | ref, err := storer.ResolveReference(fetchHead, o.ReferenceName) |
| 96 | if err != nil { |
| 97 | return err |
| 98 | } |
| 99 | |
| 100 | head, err := w.r.Head() |
| 101 | if err == nil { |
| 102 | // if we don't have a shallows list, just ignore it |
| 103 | shallowList, _ := w.r.Storer.Shallow() |
| 104 | |
| 105 | var earliestShallow *plumbing.Hash |
| 106 | if len(shallowList) > 0 { |
| 107 | earliestShallow = &shallowList[0] |
| 108 | } |
| 109 | |
| 110 | headAheadOfRef, err := isFastForward(w.r.Storer, ref.Hash(), head.Hash(), earliestShallow) |
| 111 | if err != nil { |
| 112 | return err |
| 113 | } |
| 114 | |
| 115 | if !updated && headAheadOfRef { |
| 116 | return NoErrAlreadyUpToDate |
| 117 | } |
| 118 | |
| 119 | ff, err := isFastForward(w.r.Storer, head.Hash(), ref.Hash(), earliestShallow) |
| 120 | if err != nil { |
| 121 | return err |
no test coverage detected