@@ -42,7 +42,8 @@ class Git(LazyMixin):
4242 of the command to stdout.
4343 Set its value to 'full' to see details about the returned values.
4444 """
45- __slots__ = ("_working_dir" , "cat_file_all" , "cat_file_header" , "_version_info" )
45+ __slots__ = ("_working_dir" , "cat_file_all" , "cat_file_header" , "_version_info" ,
46+ "_git_options" )
4647
4748 # CONFIGURATION
4849 # The size in bytes read from stdout when copying git's output to another stream
@@ -217,7 +218,8 @@ def __init__(self, working_dir=None):
217218 .git directory in case of bare repositories."""
218219 super (Git , self ).__init__ ()
219220 self ._working_dir = working_dir
220-
221+ self ._git_options = ()
222+
221223 # cached command slots
222224 self .cat_file_header = None
223225 self .cat_file_all = None
@@ -386,15 +388,18 @@ def execute(self, command,
386388 else :
387389 return stdout_value
388390
389- def transform_kwargs (self , ** kwargs ):
391+ def transform_kwargs (self , split_single_char_options = False , ** kwargs ):
390392 """Transforms Python style kwargs into git command line options."""
391393 args = list ()
392394 for k , v in kwargs .items ():
393395 if len (k ) == 1 :
394396 if v is True :
395397 args .append ("-%s" % k )
396398 elif type (v ) is not bool :
397- args .append ("-%s%s" % (k , v ))
399+ if split_single_char_options :
400+ args .extend (["-%s" % k , "%s" % v ])
401+ else :
402+ args .append ("-%s%s" % (k , v ))
398403 else :
399404 if v is True :
400405 args .append ("--%s" % dashify (k ))
@@ -417,6 +422,22 @@ def __unpack_args(cls, arg_list):
417422 # END for each arg
418423 return outlist
419424
425+ def __call__ (self , ** kwargs ):
426+ """Specify command line options to the git executable
427+ for a subcommand call
428+
429+ :param kwargs:
430+ is a dict of keyword arguments.
431+ these arguments are passed as in _call_process
432+ but will be passed to the git command rather than
433+ the subcommand.
434+
435+ ``Examples``::
436+ git(work_tree='/tmp').difftool()"""
437+ self ._git_options = self .transform_kwargs (
438+ split_single_char_options = True , ** kwargs )
439+ return self
440+
420441 def _call_process (self , method , * args , ** kwargs ):
421442 """Run the given git command with the specified arguments and return
422443 the result as a String
@@ -455,7 +476,14 @@ def _call_process(self, method, *args, **kwargs):
455476 args = opt_args + ext_args
456477
457478 def make_call ():
458- call = [self .GIT_PYTHON_GIT_EXECUTABLE , dashify (method )]
479+ call = [self .GIT_PYTHON_GIT_EXECUTABLE ]
480+
481+ # add the git options, the reset to empty
482+ # to avoid side_effects
483+ call .extend (self ._git_options )
484+ self ._git_options = ()
485+
486+ call .extend ([dashify (method )])
459487 call .extend (args )
460488 return call
461489 #END utility to recreate call after changes
0 commit comments