summaryrefslogtreecommitdiff
path: root/lib/git/cmd.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/git/cmd.py')
-rw-r--r--lib/git/cmd.py25
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/git/cmd.py b/lib/git/cmd.py
index 1a764ed3..bd8da4ca 100644
--- a/lib/git/cmd.py
+++ b/lib/git/cmd.py
@@ -81,6 +81,7 @@ class Git(MethodMissingMixin):
with_stderr=False,
with_exceptions=False,
with_raw_output=False,
+ with_keep_cwd=False,
):
"""
Handles executing the command on the shell and consumes and returns
@@ -104,6 +105,9 @@ class Git(MethodMissingMixin):
``with_raw_output``
Whether to avoid stripping off trailing whitespace.
+ ``with_keep_cwd``
+ Whether to use the current working directory from os.getcwd().
+
Returns
str(output) # with_status = False (Default)
tuple(int(status), str(output)) # with_status = True
@@ -119,9 +123,15 @@ class Git(MethodMissingMixin):
else:
stderr = subprocess.PIPE
+ # Allow the user to have the command executed in their working dir.
+ if with_keep_cwd:
+ cwd = os.getcwd()
+ else:
+ cwd=self._cwd
+
# Start the process
proc = subprocess.Popen(command,
- cwd=self._cwd,
+ cwd=cwd,
stdin=istream,
stderr=stderr,
stdout=subprocess.PIPE
@@ -132,6 +142,10 @@ class Git(MethodMissingMixin):
status = proc.wait()
proc.stdout.close()
+ if proc.stderr:
+ stderr_value = proc.stderr.read()
+ proc.stderr.close()
+
# Strip off trailing whitespace by default
if not with_raw_output:
stdout_value = stdout_value.rstrip()
@@ -143,7 +157,12 @@ class Git(MethodMissingMixin):
% (str(command), status))
if GIT_PYTHON_TRACE == 'full':
- print "%s %d: '%s'" % (command, status, stdout_value)
+ if stderr_value:
+ print "%s -> %d: '%s' !! '%s'" % (command, status, stdout_value, stderr_value)
+ elif stdout_value:
+ print "%s -> %d: '%s'" % (command, status, stdout_value)
+ else:
+ print "%s -> %d" % (command, status)
# Allow access to the command's status code
if with_status:
@@ -199,6 +218,7 @@ class Git(MethodMissingMixin):
with_stderr = kwargs.pop("with_stderr", None)
with_exceptions = kwargs.pop("with_exceptions", None)
with_raw_output = kwargs.pop("with_raw_output", None)
+ with_keep_cwd = kwargs.pop("with_keep_cwd", None)
# Prepare the argument list
opt_args = self.transform_kwargs(**kwargs)
@@ -214,4 +234,5 @@ class Git(MethodMissingMixin):
with_stderr = with_stderr,
with_exceptions = with_exceptions,
with_raw_output = with_raw_output,
+ with_keep_cwd = with_keep_cwd,
)