aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2012-01-31 08:48:06 +0100
committerGuido Günther <agx@sigxcpu.org>2012-01-31 09:38:09 +0100
commit041dbf23affac5aafdcc876fceaab29a0133f4fc (patch)
tree9ac0b20e0f7248e89bf60ed732950f2fa963cdeb
parent45ab61b5e0ae338e2e28b562c15b4d5b5ea52390 (diff)
GitRepository: allow to capture stderr in __git_inout
stderr was always None.
-rw-r--r--gbp/git/repository.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py
index 6af56df..cb688f5 100644
--- a/gbp/git/repository.py
+++ b/gbp/git/repository.py
@@ -104,7 +104,8 @@ class GitRepository(object):
output += popen.stdout.readlines()
return output, popen.returncode
- def __git_inout(self, command, args, input, extra_env=None):
+ def __git_inout(self, command, args, input, extra_env=None, cwd=None,
+ capture_stderr=False):
"""
Run a git command with input and return output
@@ -116,15 +117,23 @@ class GitRepository(object):
@type args: C{list}
@param extra_env: extra environment variables to pass
@type extra_env: C{dict}
+ @param capture_stderr: whether to capture stderr
+ @type capture_stderr: C{bool}
@return: stdout, stderr, return code
- @rtype: C{tuple}
+ @rtype: C{tuple} of C{str}, C{str}, C{int}
"""
+ if not cwd:
+ cwd = self.path
+
+ stderr_arg = subprocess.PIPE if capture_stderr else None
+
env = self.__build_env(extra_env)
cmd = ['git', command] + args
log.debug(cmd)
popen = subprocess.Popen(cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
+ stderr=stderr_arg,
env=env,
cwd=self.path)
(stdout, stderr) = popen.communicate(input)
@@ -982,7 +991,11 @@ class GitRepository(object):
args = [ tree ]
for parent in parents:
args += [ '-p' , parent ]
- sha1, stderr, ret = self.__git_inout('commit-tree', args, msg, extra_env)
+ sha1, stderr, ret = self.__git_inout('commit-tree',
+ args,
+ msg,
+ extra_env,
+ capture_stderr=True)
if not ret:
return sha1.strip()
else: