Skip to content

Commit 7e38cd2

Browse files
committed
Enable automatic proxy detection for remote fetch()
See #642
1 parent dbdacd9 commit 7e38cd2

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

pygit2/remote.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def save(self):
106106
err = C.git_remote_save(self._remote)
107107
check_error(err)
108108

109-
def fetch(self, refspecs=None, message=None, callbacks=None, prune=C.GIT_FETCH_PRUNE_UNSPECIFIED):
109+
def fetch(self, refspecs=None, message=None, callbacks=None, prune=C.GIT_FETCH_PRUNE_UNSPECIFIED, proxy=None):
110110
"""Perform a fetch against this remote. Returns a <TransferProgress>
111111
object.
112112
@@ -118,11 +118,23 @@ def fetch(self, refspecs=None, message=None, callbacks=None, prune=C.GIT_FETCH_P
118118
repo, the second will remove any remote branch in the local
119119
repository that does not exist in the remote and the last will
120120
always keep the remote branches
121+
122+
proxy : None or True or str
123+
Proxy configuration. Can be one of:
124+
125+
* `None` (the default) to disable proxy usage
126+
* `True` to enable automatic proxy detection
127+
* an url to a proxy (`http://proxy.example.org:3128/`)
121128
"""
122129
message = to_bytes(message)
123130
with git_fetch_options(callbacks) as payload:
124131
opts = payload.fetch_options
125132
opts.prune = prune
133+
if proxy is True:
134+
opts.proxy_opts.type = C.GIT_PROXY_AUTO
135+
elif proxy is not None:
136+
opts.proxy_opts.type = C.GIT_PROXY_SPECIFIED
137+
opts.proxy_opts.url = proxy
126138
with StrArray(refspecs) as arr:
127139
err = C.git_remote_fetch(self._remote, arr, opts, to_bytes(message))
128140
payload.check_error(err)

0 commit comments

Comments
 (0)