summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>2014-02-06 09:17:56 +0200
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>2014-02-07 14:25:26 +0200
commit2a273775d26ff8abb2ee8642388c3d2d35031270 (patch)
tree368bd323ae6626dbfeeb1b14bc4dfc152e55582f
parent4188efd97f798bc4a32c34b3791388fba59b13cf (diff)
downloadgit-buildpackage-2a273775d26ff8abb2ee8642388c3d2d35031270.tar.gz
git-buildpackage-2a273775d26ff8abb2ee8642388c3d2d35031270.tar.bz2
git-buildpackage-2a273775d26ff8abb2ee8642388c3d2d35031270.zip
GitRepository: allow interactive commands
Make it possible for git commands to output directly to stdout without redirection (i.e. capturing their stdout stream). Change-Id: I157b004c03452802a162fbf1765c81168b448b66 Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
-rw-r--r--gbp/git/repository.py29
1 files changed, 19 insertions, 10 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py
index b582f647..8bb71f2f 100644
--- a/gbp/git/repository.py
+++ b/gbp/git/repository.py
@@ -159,7 +159,7 @@ class GitRepository(object):
return output, popen.returncode
def _git_inout(self, command, args, input=None, extra_env=None, cwd=None,
- capture_stderr=False):
+ capture_stderr=False, capture_stdout=True):
"""
Run a git command with input and return output
@@ -183,7 +183,8 @@ class GitRepository(object):
stderr = ''
try:
for outdata in self.__git_inout(command, args, input, extra_env,
- cwd, capture_stderr):
+ cwd, capture_stderr,
+ capture_stdout):
stdout += outdata[0]
stderr += outdata[1]
except GitRepositoryError as err:
@@ -205,7 +206,7 @@ class GitRepository(object):
stderr = ''
try:
for outdata in self.__git_inout(command, args, stdin, extra_env,
- cwd, capture_stderr):
+ cwd, capture_stderr, True):
stderr += outdata[1]
yield outdata[0]
except GitRepositoryError as err:
@@ -213,7 +214,8 @@ class GitRepository(object):
raise err
@classmethod
- def __git_inout(cls, command, args, stdin, extra_env, cwd, capture_stderr):
+ def __git_inout(cls, command, args, stdin, extra_env, cwd, capture_stderr,
+ capture_stdout):
"""
Run a git command without a a GitRepostitory instance.
@@ -229,18 +231,21 @@ class GitRepository(object):
cmd = ['git', command] + args
env = cls.__build_env(extra_env)
+ stdout_arg = subprocess.PIPE if capture_stdout else None
stdin_arg = subprocess.PIPE if stdin else None
stderr_arg = subprocess.PIPE if capture_stderr else None
log.debug(cmd)
popen = subprocess.Popen(cmd,
stdin=stdin_arg,
- stdout=subprocess.PIPE,
+ stdout=stdout_arg,
stderr=stderr_arg,
env=env,
close_fds=True,
cwd=cwd)
- out_fds = [popen.stdout] + ([popen.stderr] if capture_stderr else [])
+ out_fds = [popen.stdout] if capture_stdout else []
+ if capture_stderr:
+ out_fds.append(popen.stderr)
in_fds = [popen.stdin] if stdin else []
w_ind = 0
while out_fds or in_fds:
@@ -265,7 +270,7 @@ class GitRepository(object):
err.returncode = popen.returncode
raise err
- def _git_command(self, command, args=[], extra_env=None):
+ def _git_command(self, command, args=[], extra_env=None, interactive=False):
"""
Execute git command with arguments args and environment env
at path.
@@ -277,12 +282,14 @@ class GitRepository(object):
@param extra_env: extra environment variables to set when running command
@type extra_env: C{dict}
"""
+ capture_stdout = not interactive
try:
stdout, stderr, ret = self._git_inout(command=command,
args=args,
input=None,
extra_env=extra_env,
- capture_stderr=True)
+ capture_stderr=True,
+ capture_stdout=capture_stdout)
except Exception as excobj:
raise GitRepositoryError("Error running git %s: %s" % (command, excobj))
if ret:
@@ -1961,7 +1968,8 @@ class GitRepository(object):
stdin=None,
extra_env=None,
cwd=abspath,
- capture_stderr=True):
+ capture_stderr=True,
+ capture_stdout=True):
stderr += out[1]
except GitRepositoryError:
raise GitRepositoryError("Error running git init: %s" % stderr)
@@ -2024,7 +2032,8 @@ class GitRepository(object):
stdin=None,
extra_env=None,
cwd=abspath,
- capture_stderr=True):
+ capture_stderr=True,
+ capture_stdout=True):
stderr += out[1]
except GitRepositoryError:
raise GitRepositoryError("Error running git clone: %s" % stderr)