@@ -91,12 +91,23 @@ def push_url(self):
91
91
92
92
return maybe_string (C .git_remote_pushurl (self ._remote ))
93
93
94
- def connect (self , callbacks = None , direction = C .GIT_DIRECTION_FETCH ):
94
+ def connect (self , callbacks = None , direction = C .GIT_DIRECTION_FETCH , proxy = None ):
95
95
"""Connect to the remote.
96
+
97
+ Parameters:
98
+
99
+ proxy : None or True or str
100
+ Proxy configuration. Can be one of:
101
+
102
+ * `None` (the default) to disable proxy usage
103
+ * `True` to enable automatic proxy detection
104
+ * an url to a proxy (`http://proxy.example.org:3128/`)
96
105
"""
106
+ proxy_opts = ffi .new ('git_proxy_options *' )
107
+ Remote ._set_proxy (proxy_opts , proxy )
97
108
with git_remote_callbacks (callbacks ) as payload :
98
109
err = C .git_remote_connect (self ._remote , direction ,
99
- payload .remote_callbacks , ffi . NULL ,
110
+ payload .remote_callbacks , proxy_opts ,
100
111
ffi .NULL )
101
112
payload .check_error (err )
102
113
@@ -106,7 +117,7 @@ def save(self):
106
117
err = C .git_remote_save (self ._remote )
107
118
check_error (err )
108
119
109
- def fetch (self , refspecs = None , message = None , callbacks = None , prune = C .GIT_FETCH_PRUNE_UNSPECIFIED ):
120
+ def fetch (self , refspecs = None , message = None , callbacks = None , prune = C .GIT_FETCH_PRUNE_UNSPECIFIED , proxy = None ):
110
121
"""Perform a fetch against this remote. Returns a <TransferProgress>
111
122
object.
112
123
@@ -118,24 +129,38 @@ def fetch(self, refspecs=None, message=None, callbacks=None, prune=C.GIT_FETCH_P
118
129
repo, the second will remove any remote branch in the local
119
130
repository that does not exist in the remote and the last will
120
131
always keep the remote branches
132
+
133
+ proxy : None or True or str
134
+ Proxy configuration. Can be one of:
135
+
136
+ * `None` (the default) to disable proxy usage
137
+ * `True` to enable automatic proxy detection
138
+ * an url to a proxy (`http://proxy.example.org:3128/`)
121
139
"""
122
140
message = to_bytes (message )
123
141
with git_fetch_options (callbacks ) as payload :
124
142
opts = payload .fetch_options
125
143
opts .prune = prune
144
+ Remote ._set_proxy (opts .proxy_opts , proxy )
126
145
with StrArray (refspecs ) as arr :
127
146
err = C .git_remote_fetch (self ._remote , arr , opts , to_bytes (message ))
128
147
payload .check_error (err )
129
148
130
149
return TransferProgress (C .git_remote_stats (self ._remote ))
131
150
132
- def ls_remotes (self , callbacks = None ):
151
+ def ls_remotes (self , callbacks = None , proxy = None ):
133
152
"""
134
153
Return a list of dicts that maps to `git_remote_head` from a
135
154
`ls_remotes` call.
155
+
156
+ Parameters:
157
+
158
+ callbacks : Passed to connect()
159
+
160
+ proxy : Passed to connect()
136
161
"""
137
162
138
- self .connect (callbacks = callbacks )
163
+ self .connect (callbacks = callbacks , proxy = proxy )
139
164
140
165
refs = ffi .new ('git_remote_head ***' )
141
166
refs_len = ffi .new ('size_t *' )
@@ -201,7 +226,7 @@ def push_refspecs(self):
201
226
202
227
return strarray_to_strings (specs )
203
228
204
- def push (self , specs , callbacks = None ):
229
+ def push (self , specs , callbacks = None , proxy = None ):
205
230
"""
206
231
Push the given refspec to the remote. Raises ``GitError`` on protocol
207
232
error or unpack failure.
@@ -216,13 +241,33 @@ def push(self, specs, callbacks=None):
216
241
217
242
specs : [str]
218
243
Push refspecs to use.
244
+
245
+ proxy : None or True or str
246
+ Proxy configuration. Can be one of:
247
+
248
+ * `None` (the default) to disable proxy usage
249
+ * `True` to enable automatic proxy detection
250
+ * an url to a proxy (`http://proxy.example.org:3128/`)
219
251
"""
220
252
with git_push_options (callbacks ) as payload :
221
253
opts = payload .push_options
254
+ Remote ._set_proxy (opts .proxy_opts , proxy )
222
255
with StrArray (specs ) as refspecs :
223
256
err = C .git_remote_push (self ._remote , refspecs , opts )
224
257
payload .check_error (err )
225
258
259
+ @staticmethod
260
+ def _set_proxy (proxy_opts , proxy ):
261
+ if proxy is None :
262
+ proxy_opts .type = C .GIT_PROXY_NONE
263
+ elif proxy is True :
264
+ proxy_opts .type = C .GIT_PROXY_AUTO
265
+ elif type (proxy ) is str :
266
+ proxy_opts .type = C .GIT_PROXY_SPECIFIED
267
+ proxy_opts .url = to_bytes (proxy )
268
+ else :
269
+ raise TypeError ("Proxy must be None, True, or a string" )
270
+
226
271
227
272
class RemoteCollection :
228
273
"""Collection of configured remotes
0 commit comments