Skip to content

Commit 4a771ad

Browse files
committed
fix(remote): assert fetch respec is set
It turns out we can't deal do fetches if no refspec is set as git will change the format of the fetch return values, providing less information than usual. A test was added to show that such a case will fail, and an assertion will assure we don't attempt to fetch/pull if there is no refspec for 'fetch'. Closes #296
1 parent 982eefb commit 4a771ad

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Diff for: git/remote.py

+14
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,18 @@ def stdout_handler(line):
604604
raise
605605
return output
606606

607+
def _assert_refspec(self):
608+
"""Turns out we can't deal with remotes if the refspec is missing"""
609+
config = self.config_reader
610+
try:
611+
if config.get_value('fetch', default=type) is type:
612+
msg = "Remote '%s' has no refspec set.\n"
613+
msg += "You can set it as follows:"
614+
msg += " 'git config --add \"remote.%s.fetch +refs/heads/*:refs/heads/*\"'." % self.name
615+
raise AssertionError(msg)
616+
finally:
617+
config.release()
618+
607619
def fetch(self, refspec=None, progress=None, **kwargs):
608620
"""Fetch the latest changes for this remote
609621
@@ -631,6 +643,7 @@ def fetch(self, refspec=None, progress=None, **kwargs):
631643
:note:
632644
As fetch does not provide progress information to non-ttys, we cannot make
633645
it available here unfortunately as in the 'push' method."""
646+
self._assert_refspec()
634647
kwargs = add_progress(kwargs, self.repo.git, progress)
635648
if isinstance(refspec, list):
636649
args = refspec
@@ -651,6 +664,7 @@ def pull(self, refspec=None, progress=None, **kwargs):
651664
:param progress: see 'push' method
652665
:param kwargs: Additional arguments to be passed to git-pull
653666
:return: Please see 'fetch' method """
667+
self._assert_refspec()
654668
kwargs = add_progress(kwargs, self.repo.git, progress)
655669
proc = self.repo.git.pull(self, refspec, with_extended_output=True, as_process=True, v=True, **kwargs)
656670
res = self._get_fetch_info_from_stderr(proc, progress or RemoteProgress())

Diff for: git/test/test_remote.py

+5
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,11 @@ def test_fetch_info(self):
494494
fetch_info_line_fmt = "c437ee5deb8d00cf02f03720693e4c802e99f390 not-for-merge %s '0.3' of "
495495
fetch_info_line_fmt += "git://github.com/gitpython-developers/GitPython"
496496
remote_info_line_fmt = "* [new branch] nomatter -> %s"
497+
498+
self.failUnlessRaises(ValueError, FetchInfo._from_line, self.rorepo,
499+
remote_info_line_fmt % "refs/something/branch",
500+
"269c498e56feb93e408ed4558c8138d750de8893\t\t/Users/ben/test/foo\n")
501+
497502
fi = FetchInfo._from_line(self.rorepo,
498503
remote_info_line_fmt % "local/master",
499504
fetch_info_line_fmt % 'remote-tracking branch')

0 commit comments

Comments
 (0)