@@ -23,6 +23,7 @@ def get_dir(self):
2323 def execute (self , command ,
2424 istream = None ,
2525 with_status = False ,
26+ with_stderr = False ,
2627 with_exceptions = False ,
2728 ):
2829 """
@@ -38,6 +39,9 @@ def execute(self, command,
3839 ``with_status``
3940 Whether to return a (status, str) tuple.
4041
42+ ``with_stderr``
43+ Whether to combine stderr into the output.
44+
4145 ``with_exceptions``
4246 Whether to raise an exception when git returns a non-zero status.
4347 Returns
@@ -48,16 +52,26 @@ def execute(self, command,
4852 if GIT_PYTHON_TRACE :
4953 print command
5054
55+ # Allow stderr to be merged into stdout when with_stderr is True.
56+ # Otherwise, throw stderr away.
57+ if with_stderr :
58+ stderr = subprocess .STDOUT
59+ else :
60+ stderr = subprocess .PIPE
61+
5162 # Start the process
5263 proc = subprocess .Popen (command ,
5364 cwd = self .git_dir ,
5465 stdin = istream ,
66+ stderr = stderr ,
5567 stdout = subprocess .PIPE
5668 )
5769
5870 # Wait for the process to return
5971 stdout_value , err = proc .communicate ()
6072 proc .stdout .close ()
73+ if proc .stderr :
74+ proc .stderr .close ()
6175 # Grab the exit status
6276 status = proc .poll ()
6377 if with_exceptions and status != 0 :
@@ -115,6 +129,7 @@ def method_missing(self, method, *args, **kwargs):
115129 # otherwise these'll end up in args, which is bad.
116130 istream = pop_key (kwargs , "istream" )
117131 with_status = pop_key (kwargs , "with_status" )
132+ with_stderr = pop_key (kwargs , "with_stderr" )
118133 with_exceptions = pop_key (kwargs , "with_exceptions" )
119134 # Prepare the argument list
120135 opt_args = self .transform_kwargs (** kwargs )
@@ -127,5 +142,6 @@ def method_missing(self, method, *args, **kwargs):
127142 return self .execute (call ,
128143 istream = istream ,
129144 with_status = with_status ,
145+ with_stderr = with_stderr ,
130146 with_exceptions = with_exceptions ,
131147 )
0 commit comments