@@ -78,9 +78,9 @@ def get_dir(self):
7878 def execute (self , command ,
7979 istream = None ,
8080 keep_cwd = False ,
81- with_status = False ,
81+ extended_output = False ,
8282 with_stderr = False ,
83- with_exceptions = False ,
83+ with_exceptions = True ,
8484 with_raw_output = False ,
8585 ):
8686 """
@@ -98,11 +98,8 @@ def execute(self, command,
9898 GitPython uses get_work_tree() as its working directory by
9999 default and get_git_dir() for bare repositories.
100100
101- ``with_status``
102- Whether to return a (status, str) tuple.
103-
104- ``with_stderr``
105- Whether to combine stderr into the output.
101+ ``extended_output``
102+ Whether to return a (status, stdout, stderr) tuple.
106103
107104 ``with_exceptions``
108105 Whether to raise an exception when git returns a non-zero status.
@@ -111,20 +108,13 @@ def execute(self, command,
111108 Whether to avoid stripping off trailing whitespace.
112109
113110 Returns
114- str(output) # with_status = False (Default)
115- tuple(int(status), str(output)) # with_status = True
111+ str(output) # extended_output = False (Default)
112+ tuple(int(status), str(output)) # extended_output = True
116113 """
117114
118115 if GIT_PYTHON_TRACE and not GIT_PYTHON_TRACE == 'full' :
119116 print ' ' .join (command )
120117
121- # Allow stderr to be merged into stdout when with_stderr is True.
122- # Otherwise, throw stderr away.
123- if with_stderr :
124- stderr = subprocess .STDOUT
125- else :
126- stderr = subprocess .PIPE
127-
128118 # Allow the user to have the command executed in their working dir.
129119 if keep_cwd :
130120 cwd = os .getcwd ()
@@ -135,28 +125,29 @@ def execute(self, command,
135125 proc = subprocess .Popen (command ,
136126 cwd = cwd ,
137127 stdin = istream ,
138- stderr = stderr ,
128+ stderr = subprocess . PIPE ,
139129 stdout = subprocess .PIPE
140130 )
141131
142132 # Wait for the process to return
143- stdout_value = proc . stdout . read ()
144- status = proc .wait ()
145- proc .stdout . close ()
146-
147- if proc . stderr :
148- stderr_value = proc .stderr . read ()
149- proc .stderr .close ()
133+ try :
134+ stdout_value = proc .stdout . read ()
135+ stderr_value = proc .stderr . read ()
136+ status = proc . wait ()
137+ finally :
138+ proc .stdout . close ()
139+ proc .stderr .close ()
150140
151141 # Strip off trailing whitespace by default
152142 if not with_raw_output :
153143 stdout_value = stdout_value .rstrip ()
144+ stderr_value = stderr_value .rstrip ()
145+
146+ print command , status
154147
155- # Grab the exit status
156- status = proc .poll ()
157148 if with_exceptions and status != 0 :
158- raise GitCommandError ( "%s returned exit status %d"
159- % ( str ( command ) , status ) )
149+ print 19
150+ raise GitCommandError ( command , status , stderr_value )
160151
161152 if GIT_PYTHON_TRACE == 'full' :
162153 if stderr_value :
@@ -167,8 +158,8 @@ def execute(self, command,
167158 print "%s -> %d" % (command , status )
168159
169160 # Allow access to the command's status code
170- if with_status :
171- return (status , stdout_value )
161+ if extended_output :
162+ return (status , stdout_value , stderr_value )
172163 else :
173164 return stdout_value
174165
@@ -217,9 +208,9 @@ def method_missing(self, method, *args, **kwargs):
217208 # otherwise these'll end up in args, which is bad.
218209 istream = kwargs .pop ("istream" , None )
219210 keep_cwd = kwargs .pop ("keep_cwd" , None )
220- with_status = kwargs .pop ("with_status " , None )
211+ extended_output = kwargs .pop ("extended_output " , None )
221212 with_stderr = kwargs .pop ("with_stderr" , None )
222- with_exceptions = kwargs .pop ("with_exceptions" , None )
213+ with_exceptions = kwargs .pop ("with_exceptions" , True )
223214 with_raw_output = kwargs .pop ("with_raw_output" , None )
224215
225216 # Prepare the argument list
@@ -233,7 +224,7 @@ def method_missing(self, method, *args, **kwargs):
233224 return self .execute (call ,
234225 istream = istream ,
235226 keep_cwd = keep_cwd ,
236- with_status = with_status ,
227+ extended_output = extended_output ,
237228 with_stderr = with_stderr ,
238229 with_exceptions = with_exceptions ,
239230 with_raw_output = with_raw_output ,
0 commit comments