@@ -81,6 +81,7 @@ def execute(self, command,
8181 with_stderr = False ,
8282 with_exceptions = False ,
8383 with_raw_output = False ,
84+ with_keep_cwd = False ,
8485 ):
8586 """
8687 Handles executing the command on the shell and consumes and returns
@@ -104,6 +105,9 @@ def execute(self, command,
104105 ``with_raw_output``
105106 Whether to avoid stripping off trailing whitespace.
106107
108+ ``with_keep_cwd``
109+ Whether to use the current working directory from os.getcwd().
110+
107111 Returns
108112 str(output) # with_status = False (Default)
109113 tuple(int(status), str(output)) # with_status = True
@@ -119,9 +123,15 @@ def execute(self, command,
119123 else :
120124 stderr = subprocess .PIPE
121125
126+ # Allow the user to have the command executed in their working dir.
127+ if with_keep_cwd :
128+ cwd = os .getcwd ()
129+ else :
130+ cwd = self ._cwd
131+
122132 # Start the process
123133 proc = subprocess .Popen (command ,
124- cwd = self . _cwd ,
134+ cwd = cwd ,
125135 stdin = istream ,
126136 stderr = stderr ,
127137 stdout = subprocess .PIPE
@@ -132,6 +142,10 @@ def execute(self, command,
132142 status = proc .wait ()
133143 proc .stdout .close ()
134144
145+ if proc .stderr :
146+ stderr_value = proc .stderr .read ()
147+ proc .stderr .close ()
148+
135149 # Strip off trailing whitespace by default
136150 if not with_raw_output :
137151 stdout_value = stdout_value .rstrip ()
@@ -143,7 +157,12 @@ def execute(self, command,
143157 % (str (command ), status ))
144158
145159 if GIT_PYTHON_TRACE == 'full' :
146- print "%s %d: '%s'" % (command , status , stdout_value )
160+ if stderr_value :
161+ print "%s -> %d: '%s' !! '%s'" % (command , status , stdout_value , stderr_value )
162+ elif stdout_value :
163+ print "%s -> %d: '%s'" % (command , status , stdout_value )
164+ else :
165+ print "%s -> %d" % (command , status )
147166
148167 # Allow access to the command's status code
149168 if with_status :
@@ -199,6 +218,7 @@ def method_missing(self, method, *args, **kwargs):
199218 with_stderr = kwargs .pop ("with_stderr" , None )
200219 with_exceptions = kwargs .pop ("with_exceptions" , None )
201220 with_raw_output = kwargs .pop ("with_raw_output" , None )
221+ with_keep_cwd = kwargs .pop ("with_keep_cwd" , None )
202222
203223 # Prepare the argument list
204224 opt_args = self .transform_kwargs (** kwargs )
@@ -214,4 +234,5 @@ def method_missing(self, method, *args, **kwargs):
214234 with_stderr = with_stderr ,
215235 with_exceptions = with_exceptions ,
216236 with_raw_output = with_raw_output ,
237+ with_keep_cwd = with_keep_cwd ,
217238 )
0 commit comments