MCPcopy
hub / github.com/go-git/go-git / PushContext

Method PushContext

remote.go:104–235  ·  view source on GitHub ↗

PushContext performs a push to the remote. Returns NoErrAlreadyUpToDate if the remote was already up-to-date. The provided Context must be non-nil. If the context expires before the operation is complete, an error is returned. The context only affects the transport operations.

(ctx context.Context, o *PushOptions)

Source from the content-addressed store, hash-verified

102// operation is complete, an error is returned. The context only affects the
103// transport operations.
104func (r *Remote) PushContext(ctx context.Context, o *PushOptions) (err error) {
105 if err := o.Validate(); err != nil {
106 return err
107 }
108
109 if o.RemoteName != r.c.Name {
110 return fmt.Errorf("remote names don't match: %s != %s", o.RemoteName, r.c.Name)
111 }
112
113 if o.RemoteURL == "" && len(r.c.URLs) > 0 {
114 o.RemoteURL = r.c.URLs[len(r.c.URLs)-1]
115 }
116
117 s, err := newSendPackSession(o.RemoteURL, o.Auth, o.InsecureSkipTLS, o.ClientCert, o.ClientKey, o.CABundle, o.ProxyOptions)
118 if err != nil {
119 return err
120 }
121
122 defer ioutil.CheckClose(s, &err)
123
124 ar, err := s.AdvertisedReferencesContext(ctx)
125 if err != nil {
126 return err
127 }
128
129 remoteRefs, err := ar.AllReferences()
130 if err != nil {
131 return err
132 }
133
134 if err := r.checkRequireRemoteRefs(o.RequireRemoteRefs, remoteRefs); err != nil {
135 return err
136 }
137
138 isDelete := false
139 allDelete := true
140 for _, rs := range o.RefSpecs {
141 if rs.IsDelete() {
142 isDelete = true
143 } else {
144 allDelete = false
145 }
146 if isDelete && !allDelete {
147 break
148 }
149 }
150
151 if isDelete && !ar.Capabilities.Supports(capability.DeleteRefs) {
152 return ErrDeleteRefNotSupported
153 }
154
155 if o.Force {
156 for i := 0; i < len(o.RefSpecs); i++ {
157 rs := &o.RefSpecs[i]
158 if !rs.IsForceUpdate() && !rs.IsDelete() {
159 o.RefSpecs[i] = config.RefSpec("+" + rs.String())
160 }
161 }

Callers 4

TestPushContextMethod · 0.95
PushMethod · 0.95
TestPushContextMethod · 0.45

Calls 15

referencesMethod · 0.95
useRefDeltasMethod · 0.95
CheckCloseFunction · 0.92
RefSpecTypeAlias · 0.92
IsLocalEndpointFunction · 0.92
NewStorageFunction · 0.92
NewObjectLRUDefaultFunction · 0.92
ObjectsFunction · 0.92

Tested by 3

TestPushContextMethod · 0.76
TestPushContextMethod · 0.36