@@ -78,9 +78,9 @@ def get_dir(self):
78
78
def execute (self , command ,
79
79
istream = None ,
80
80
keep_cwd = False ,
81
- with_status = False ,
81
+ extended_output = False ,
82
82
with_stderr = False ,
83
- with_exceptions = False ,
83
+ with_exceptions = True ,
84
84
with_raw_output = False ,
85
85
):
86
86
"""
@@ -98,11 +98,8 @@ def execute(self, command,
98
98
GitPython uses get_work_tree() as its working directory by
99
99
default and get_git_dir() for bare repositories.
100
100
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.
106
103
107
104
``with_exceptions``
108
105
Whether to raise an exception when git returns a non-zero status.
@@ -111,20 +108,13 @@ def execute(self, command,
111
108
Whether to avoid stripping off trailing whitespace.
112
109
113
110
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
116
113
"""
117
114
118
115
if GIT_PYTHON_TRACE and not GIT_PYTHON_TRACE == 'full' :
119
116
print ' ' .join (command )
120
117
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
-
128
118
# Allow the user to have the command executed in their working dir.
129
119
if keep_cwd :
130
120
cwd = os .getcwd ()
@@ -135,28 +125,29 @@ def execute(self, command,
135
125
proc = subprocess .Popen (command ,
136
126
cwd = cwd ,
137
127
stdin = istream ,
138
- stderr = stderr ,
128
+ stderr = subprocess . PIPE ,
139
129
stdout = subprocess .PIPE
140
130
)
141
131
142
132
# 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 ()
150
140
151
141
# Strip off trailing whitespace by default
152
142
if not with_raw_output :
153
143
stdout_value = stdout_value .rstrip ()
144
+ stderr_value = stderr_value .rstrip ()
145
+
146
+ print command , status
154
147
155
- # Grab the exit status
156
- status = proc .poll ()
157
148
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 )
160
151
161
152
if GIT_PYTHON_TRACE == 'full' :
162
153
if stderr_value :
@@ -167,8 +158,8 @@ def execute(self, command,
167
158
print "%s -> %d" % (command , status )
168
159
169
160
# 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 )
172
163
else :
173
164
return stdout_value
174
165
@@ -217,9 +208,9 @@ def method_missing(self, method, *args, **kwargs):
217
208
# otherwise these'll end up in args, which is bad.
218
209
istream = kwargs .pop ("istream" , None )
219
210
keep_cwd = kwargs .pop ("keep_cwd" , None )
220
- with_status = kwargs .pop ("with_status " , None )
211
+ extended_output = kwargs .pop ("extended_output " , None )
221
212
with_stderr = kwargs .pop ("with_stderr" , None )
222
- with_exceptions = kwargs .pop ("with_exceptions" , None )
213
+ with_exceptions = kwargs .pop ("with_exceptions" , True )
223
214
with_raw_output = kwargs .pop ("with_raw_output" , None )
224
215
225
216
# Prepare the argument list
@@ -233,7 +224,7 @@ def method_missing(self, method, *args, **kwargs):
233
224
return self .execute (call ,
234
225
istream = istream ,
235
226
keep_cwd = keep_cwd ,
236
- with_status = with_status ,
227
+ extended_output = extended_output ,
237
228
with_stderr = with_stderr ,
238
229
with_exceptions = with_exceptions ,
239
230
with_raw_output = with_raw_output ,
0 commit comments