summaryrefslogtreecommitdiff
path: root/lib/git_python/git.py
diff options
context:
space:
mode:
authorDavid Aguilar <davvid@gmail.com>2008-05-29 02:16:28 -0700
committerDavid Aguilar <davvid@gmail.com>2008-05-29 02:16:28 -0700
commitc4d5e7c9dab813adf9bfd8198bb9bb00c9a9503b (patch)
tree9f27fb8406b453f52cb81bdc3b736fd4910b090e /lib/git_python/git.py
parent4a061029eddee38110e416e3c4f60d553dafc9e5 (diff)
downloadgitpython-c4d5e7c9dab813adf9bfd8198bb9bb00c9a9503b.tar.gz
git.py: add support for merging stderr into stdout
When git.foo( with_stderr=True ) is called, stderr is returned along with stdout in a merged stream. Signed-off-by: David Aguilar <davvid@gmail.com>
Diffstat (limited to 'lib/git_python/git.py')
-rw-r--r--lib/git_python/git.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/git_python/git.py b/lib/git_python/git.py
index 6d5fd1ed..00cdf40e 100644
--- a/lib/git_python/git.py
+++ b/lib/git_python/git.py
@@ -23,6 +23,7 @@ class Git(MethodMissingMixin):
def execute(self, command,
istream = None,
with_status = False,
+ with_stderr = False,
with_exceptions = False,
):
"""
@@ -38,6 +39,9 @@ class Git(MethodMissingMixin):
``with_status``
Whether to return a (status, str) tuple.
+ ``with_stderr``
+ Whether to combine stderr into the output.
+
``with_exceptions``
Whether to raise an exception when git returns a non-zero status.
Returns
@@ -48,16 +52,26 @@ class Git(MethodMissingMixin):
if GIT_PYTHON_TRACE:
print command
+ # Allow stderr to be merged into stdout when with_stderr is True.
+ # Otherwise, throw stderr away.
+ if with_stderr:
+ stderr = subprocess.STDOUT
+ else:
+ stderr = subprocess.PIPE
+
# Start the process
proc = subprocess.Popen(command,
cwd = self.git_dir,
stdin = istream,
+ stderr = stderr,
stdout = subprocess.PIPE
)
# Wait for the process to return
stdout_value, err = proc.communicate()
proc.stdout.close()
+ if proc.stderr:
+ proc.stderr.close()
# Grab the exit status
status = proc.poll()
if with_exceptions and status != 0:
@@ -115,6 +129,7 @@ class Git(MethodMissingMixin):
# otherwise these'll end up in args, which is bad.
istream = pop_key(kwargs, "istream")
with_status = pop_key(kwargs, "with_status")
+ with_stderr = pop_key(kwargs, "with_stderr")
with_exceptions = pop_key(kwargs, "with_exceptions")
# Prepare the argument list
opt_args = self.transform_kwargs(**kwargs)
@@ -127,5 +142,6 @@ class Git(MethodMissingMixin):
return self.execute(call,
istream = istream,
with_status = with_status,
+ with_stderr = with_stderr,
with_exceptions = with_exceptions,
)