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