summaryrefslogtreecommitdiff
path: root/lib/git_python
diff options
context:
space:
mode:
authorDavid Aguilar <davvid@gmail.com>2008-05-29 02:18:28 -0700
committerDavid Aguilar <davvid@gmail.com>2008-05-29 02:18:28 -0700
commit4e509130b7dfc97eeb4a517d6c9c65a8d6204234 (patch)
tree0b2290403c1474dd7ac5067edd836091aa0625a0 /lib/git_python
parent7d49273897bd317323e0a3bbbc01b76e83370f0c (diff)
downloadgitpython-4e509130b7dfc97eeb4a517d6c9c65a8d6204234.tar.gz
git.py: always strip trailing whitespace and add an option to not do so
We now strip off any trailing whitespace. We inhibit this behavior when git.foo( with_raw_output=True ) is called. Signed-off-by: David Aguilar <davvid@gmail.com>
Diffstat (limited to 'lib/git_python')
-rw-r--r--lib/git_python/git.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/git_python/git.py b/lib/git_python/git.py
index 00cdf40e..436df856 100644
--- a/lib/git_python/git.py
+++ b/lib/git_python/git.py
@@ -25,6 +25,7 @@ class Git(MethodMissingMixin):
with_status = False,
with_stderr = False,
with_exceptions = False,
+ with_raw_output = False,
):
"""
Handles executing the command on the shell and consumes and returns
@@ -44,6 +45,10 @@ class Git(MethodMissingMixin):
``with_exceptions``
Whether to raise an exception when git returns a non-zero status.
+
+ ``with_raw_output``
+ Whether to avoid stripping off trailing whitespace.
+
Returns
str(output) # with_status = False (Default)
tuple(int(status), str(output)) # with_status = True
@@ -72,6 +77,11 @@ class Git(MethodMissingMixin):
proc.stdout.close()
if proc.stderr:
proc.stderr.close()
+
+ # Strip off trailing whitespace by default
+ if not with_raw_output:
+ stdout_value = stdout_value.rstrip()
+
# Grab the exit status
status = proc.poll()
if with_exceptions and status != 0:
@@ -131,6 +141,8 @@ class Git(MethodMissingMixin):
with_status = pop_key(kwargs, "with_status")
with_stderr = pop_key(kwargs, "with_stderr")
with_exceptions = pop_key(kwargs, "with_exceptions")
+ with_raw_output = pop_key(kwargs, "with_raw_output")
+
# Prepare the argument list
opt_args = self.transform_kwargs(**kwargs)
ext_args = map(str, args)
@@ -144,4 +156,5 @@ class Git(MethodMissingMixin):
with_status = with_status,
with_stderr = with_stderr,
with_exceptions = with_exceptions,
+ with_raw_output = with_raw_output,
)