@@ -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
@@ -417,6 +419,21 @@ def __unpack_args(cls, arg_list):
417419 # END for each arg
418420 return outlist
419421
422+ def __call__ (self , ** kwargs ):
423+ """Specify command line options to the git executable
424+ for a subcommand call
425+
426+ :param kwargs:
427+ is a dict of keyword arguments.
428+ these arguments are passed as in _call_process
429+ but will be passed to the git command rather than
430+ the subcommand.
431+
432+ ``Examples``::
433+ git(work_tree='/tmp').difftool()"""
434+ self ._git_options = self .transform_kwargs (** kwargs )
435+ return self
436+
420437 def _call_process (self , method , * args , ** kwargs ):
421438 """Run the given git command with the specified arguments and return
422439 the result as a String
@@ -455,7 +472,14 @@ def _call_process(self, method, *args, **kwargs):
455472 args = opt_args + ext_args
456473
457474 def make_call ():
458- call = [self .GIT_PYTHON_GIT_EXECUTABLE , dashify (method )]
475+ call = [self .GIT_PYTHON_GIT_EXECUTABLE ]
476+
477+ # add the git options, the reset to empty
478+ # to avoid side_effects
479+ call .extend (self ._git_options )
480+ self ._git_options = ()
481+
482+ call .extend ([dashify (method )])
459483 call .extend (args )
460484 return call
461485 #END utility to recreate call after changes
0 commit comments