Skip to content

Commit 6b655be

Browse files
committed
Add version-specific behavior.
--progress is not a valid flag for earlier versions of git, so we check for the version before using it.
1 parent f0f02bb commit 6b655be

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

git/cmd.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Git(object):
4141
of the command to stdout.
4242
Set its value to 'full' to see details about the returned values.
4343
"""
44-
__slots__ = ("_working_dir", "cat_file_all", "cat_file_header")
44+
__slots__ = ("_working_dir", "cat_file_all", "cat_file_header", "_version")
4545

4646
# CONFIGURATION
4747
# The size in bytes read from stdout when copying git's output to another stream
@@ -205,6 +205,7 @@ def __init__(self, working_dir=None):
205205
.git directory in case of bare repositories."""
206206
super(Git, self).__init__()
207207
self._working_dir = working_dir
208+
self._version = self._get_version_as_tuple()
208209

209210
# cached command slots
210211
self.cat_file_header = None
@@ -513,3 +514,13 @@ def clear_cache(self):
513514
self.cat_file_all = None
514515
self.cat_file_header = None
515516
return self
517+
518+
def _get_version_as_tuple(self):
519+
""" Get and parse git version string. """
520+
version_str = self._call_process('version')
521+
version_numbers = version_str.rpartition(' ')[2]
522+
return tuple(version_numbers.split('.'))
523+
524+
@property
525+
def version(self):
526+
return self._version

git/remote.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,8 @@ def fetch(self, refspec=None, progress=None, **kwargs):
514514
:note:
515515
As fetch does not provide progress information to non-ttys, we cannot make
516516
it available here unfortunately as in the 'push' method."""
517-
proc = self.repo.git.fetch(self, refspec, with_extended_output=True, as_process=True, v=True, progress=True, **kwargs)
517+
if self.repo.git.version >= (1, 7, 0, 0): kwargs['progress'] = True
518+
proc = self.repo.git.fetch(self, refspec, with_extended_output=True, as_process=True, v=True, **kwargs)
518519
return self._get_fetch_info_from_stderr(proc, progress or RemoteProgress())
519520

520521
def pull(self, refspec=None, progress=None, **kwargs):
@@ -525,7 +526,8 @@ def pull(self, refspec=None, progress=None, **kwargs):
525526
:param progress: see 'push' method
526527
:param kwargs: Additional arguments to be passed to git-pull
527528
:return: Please see 'fetch' method """
528-
proc = self.repo.git.pull(self, refspec, with_extended_output=True, as_process=True, v=True, progress=True, **kwargs)
529+
if self.repo.git.version >= (1, 7, 0, 0): kwargs['progress'] = True
530+
proc = self.repo.git.pull(self, refspec, with_extended_output=True, as_process=True, v=True, **kwargs)
529531
return self._get_fetch_info_from_stderr(proc, progress or RemoteProgress())
530532

531533
def push(self, refspec=None, progress=None, **kwargs):
@@ -546,7 +548,8 @@ def push(self, refspec=None, progress=None, **kwargs):
546548
in their flags.
547549
If the operation fails completely, the length of the returned IterableList will
548550
be null."""
549-
proc = self.repo.git.push(self, refspec, porcelain=True, as_process=True, progress=True, **kwargs)
551+
if self.repo.git.version >= (1, 7, 0, 0): kwargs['progress'] = True
552+
proc = self.repo.git.push(self, refspec, porcelain=True, as_process=True, progress=True, v=True, **kwargs)
550553
return self._get_push_info(proc, progress or RemoteProgress())
551554

552555
@property

git/repo/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,8 @@ def _clone(cls, git, url, path, odb_default_type, progress, **kwargs):
684684
# END windows handling
685685

686686
try:
687-
proc = git.clone(url, path, with_extended_output=True, as_process=True, v=True, progress=True, **kwargs)
687+
if git.version >= (1, 7, 0, 0): kwargs['progress'] = True
688+
proc = git.clone(url, path, with_extended_output=True, as_process=True, v=True, **kwargs)
688689
if progress:
689690
_digest_process_messages(proc.stderr, progress)
690691
_finalize_proc(proc)

0 commit comments

Comments
 (0)