Skip to content

Progress parsing #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add version-specific behavior.
--progress is not a valid flag for earlier versions of git, so we check
for the version before using it.
  • Loading branch information
int3 committed May 24, 2011
commit 6b655beb8865b5ea3d19bb42e45fedbfc25e6624
13 changes: 12 additions & 1 deletion git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Git(object):
of the command to stdout.
Set its value to 'full' to see details about the returned values.
"""
__slots__ = ("_working_dir", "cat_file_all", "cat_file_header")
__slots__ = ("_working_dir", "cat_file_all", "cat_file_header", "_version")

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

# cached command slots
self.cat_file_header = None
Expand Down Expand Up @@ -513,3 +514,13 @@ def clear_cache(self):
self.cat_file_all = None
self.cat_file_header = None
return self

def _get_version_as_tuple(self):
""" Get and parse git version string. """
version_str = self._call_process('version')
version_numbers = version_str.rpartition(' ')[2]
return tuple(version_numbers.split('.'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you forgot to convert the strings to integers.
The line should be something like

tuple(int(n) for n in version_numbers.split('.'))


@property
def version(self):
return self._version
9 changes: 6 additions & 3 deletions git/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,8 @@ def fetch(self, refspec=None, progress=None, **kwargs):
:note:
As fetch does not provide progress information to non-ttys, we cannot make
it available here unfortunately as in the 'push' method."""
proc = self.repo.git.fetch(self, refspec, with_extended_output=True, as_process=True, v=True, progress=True, **kwargs)
if self.repo.git.version >= (1, 7, 0, 0): kwargs['progress'] = True
proc = self.repo.git.fetch(self, refspec, with_extended_output=True, as_process=True, v=True, **kwargs)
return self._get_fetch_info_from_stderr(proc, progress or RemoteProgress())

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

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

@property
Expand Down
3 changes: 2 additions & 1 deletion git/repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,8 @@ def _clone(cls, git, url, path, odb_default_type, progress, **kwargs):
# END windows handling

try:
proc = git.clone(url, path, with_extended_output=True, as_process=True, v=True, progress=True, **kwargs)
if git.version >= (1, 7, 0, 0): kwargs['progress'] = True
proc = git.clone(url, path, with_extended_output=True, as_process=True, v=True, **kwargs)
if progress:
_digest_process_messages(proc.stderr, progress)
_finalize_proc(proc)
Expand Down