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

Method PushContext

remote.go:103–234  ·  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

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

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