88# Enables debugging of GitPython's git commands
99GIT_PYTHON_TRACE = os .environ .get ("GIT_PYTHON_TRACE" , False )
1010
11+ execute_kwargs = ('istream' , 'with_keep_cwd' , 'with_extended_output' ,
12+ 'with_exceptions' , 'with_raw_output' )
13+
1114class Git (MethodMissingMixin ):
1215 """
1316 The Git class manages communication with the Git binary
@@ -77,9 +80,8 @@ def get_dir(self):
7780
7881 def execute (self , command ,
7982 istream = None ,
80- keep_cwd = False ,
81- extended_output = False ,
82- with_stderr = False ,
83+ with_keep_cwd = False ,
84+ with_extended_output = False ,
8385 with_exceptions = True ,
8486 with_raw_output = False ,
8587 ):
@@ -93,12 +95,12 @@ def execute(self, command,
9395 ``istream``
9496 Standard input filehandle passed to subprocess.Popen.
9597
96- ``keep_cwd ``
98+ ``with_keep_cwd ``
9799 Whether to use the current working directory from os.getcwd().
98100 GitPython uses get_work_tree() as its working directory by
99101 default and get_git_dir() for bare repositories.
100102
101- ``extended_output ``
103+ ``with_extended_output ``
102104 Whether to return a (status, stdout, stderr) tuple.
103105
104106 ``with_exceptions``
@@ -116,7 +118,7 @@ def execute(self, command,
116118 print ' ' .join (command )
117119
118120 # Allow the user to have the command executed in their working dir.
119- if keep_cwd :
121+ if with_keep_cwd :
120122 cwd = os .getcwd ()
121123 else :
122124 cwd = self ._cwd
@@ -143,10 +145,7 @@ def execute(self, command,
143145 stdout_value = stdout_value .rstrip ()
144146 stderr_value = stderr_value .rstrip ()
145147
146- print command , status
147-
148148 if with_exceptions and status != 0 :
149- print 19
150149 raise GitCommandError (command , status , stderr_value )
151150
152151 if GIT_PYTHON_TRACE == 'full' :
@@ -158,7 +157,7 @@ def execute(self, command,
158157 print "%s -> %d" % (command , status )
159158
160159 # Allow access to the command's status code
161- if extended_output :
160+ if with_extended_output :
162161 return (status , stdout_value , stderr_value )
163162 else :
164163 return stdout_value
@@ -206,12 +205,12 @@ def method_missing(self, method, *args, **kwargs):
206205
207206 # Handle optional arguments prior to calling transform_kwargs
208207 # otherwise these'll end up in args, which is bad.
209- istream = kwargs . pop ( "istream" , None )
210- keep_cwd = kwargs . pop ( "keep_cwd" , None )
211- extended_output = kwargs . pop ( "extended_output" , None )
212- with_stderr = kwargs .pop ("with_stderr" , None )
213- with_exceptions = kwargs . pop ( "with_exceptions" , True )
214- with_raw_output = kwargs . pop ( "with_raw_output" , None )
208+ _kwargs = {}
209+ for kwarg in execute_kwargs :
210+ try :
211+ _kwargs [ kwarg ] = kwargs .pop (kwarg )
212+ except KeyError :
213+ pass
215214
216215 # Prepare the argument list
217216 opt_args = self .transform_kwargs (** kwargs )
@@ -221,11 +220,4 @@ def method_missing(self, method, *args, **kwargs):
221220 call = ["git" , dashify (method )]
222221 call .extend (args )
223222
224- return self .execute (call ,
225- istream = istream ,
226- keep_cwd = keep_cwd ,
227- extended_output = extended_output ,
228- with_stderr = with_stderr ,
229- with_exceptions = with_exceptions ,
230- with_raw_output = with_raw_output ,
231- )
223+ return self .execute (call , ** _kwargs )
0 commit comments