Skip to content

Commit 237d47b

Browse files
committed
Support multiple refspecs in fetch.
Git supports fetching many refs at once - support this in GitPython too for more efficient operations when selectively mirroring repositories.
1 parent 5ae512e commit 237d47b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

‎git/remote.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,10 @@ def fetch(self, refspec=None, progress=None, **kwargs):
583583
See also git-push(1).
584584
585585
Taken from the git manual
586+
587+
Fetch supports multiple refspecs (as the
588+
underlying git-fetch does) - supplying a list rather than a string
589+
for 'refspec' will make use of this facility.
586590
:param progress: See 'push' method
587591
:param kwargs: Additional arguments to be passed to git-fetch
588592
:return:
@@ -593,7 +597,11 @@ def fetch(self, refspec=None, progress=None, **kwargs):
593597
As fetch does not provide progress information to non-ttys, we cannot make
594598
it available here unfortunately as in the 'push' method."""
595599
kwargs=add_progress(kwargs, self.repo.git, progress)
596-
proc=self.repo.git.fetch(self, refspec, with_extended_output=True, as_process=True, v=True, **kwargs)
600+
ifisinstance(refspec, list):
601+
args=refspec
602+
else:
603+
args= [refspec]
604+
proc=self.repo.git.fetch(self, *args, with_extended_output=True, as_process=True, v=True, **kwargs)
597605
returnself._get_fetch_info_from_stderr(proc, progressorRemoteProgress())
598606

599607
defpull(self, refspec=None, progress=None, **kwargs):

‎git/test/test_remote.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ def get_info(res, remote, name):
199199
# ... with respec and no target
200200
res=fetch_and_test(remote, refspec='master')
201201
assertlen(res) ==1
202+
203+
# ... multiple refspecs
204+
res=fetch_and_test(remote, refspec=['master', 'fred'])
205+
assertlen(res) ==1
202206

203207
# add new tag reference
204208
rtag=TagReference.create(remote_repo, "1.0-RV_hello.there")

0 commit comments

Comments
(0)