MCPcopy Create free account
hub / github.com/go-git/go-git / PullContext

Method PullContext

worktree.go:63–149  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 1

PullMethod · 0.95

Calls 11

updateHEADMethod · 0.95
ResetMethod · 0.95
updateSubmodulesMethod · 0.95
ResolveReferenceFunction · 0.92
isFastForwardFunction · 0.85
RemoteMethod · 0.80
fetchMethod · 0.80
HeadMethod · 0.80
ShallowMethod · 0.65
HashMethod · 0.65
ValidateMethod · 0.45

Tested by

no test coverage detected