summaryrefslogtreecommitdiff
path: root/git/cmd.py
diff options
context:
space:
mode:
authorEric Brunson <ebrunson@quicinc.com>2014-04-23 11:13:54 -0600
committerEric Brunson <ebrunson@quicinc.com>2014-04-23 11:13:54 -0600
commite54cd8fed2d1788618df64b319a30c7aed791191 (patch)
tree21a3660972276a527a4d301e1d3742f22ec51d77 /git/cmd.py
parente6a2942a982c2541a6b6f7c67aa7dbf57ed060ca (diff)
downloadgitpython-e54cd8fed2d1788618df64b319a30c7aed791191.tar.gz
add git command options
Add __call__ method to Git object to allow passing git command options to the executable Change-Id: If1bc01008e66d3fd3811c15b56e58f38c95b9887
Diffstat (limited to 'git/cmd.py')
-rw-r--r--git/cmd.py30
1 files changed, 27 insertions, 3 deletions
diff --git a/git/cmd.py b/git/cmd.py
index 2d4aa727..e57bb761 100644
--- a/git/cmd.py
+++ b/git/cmd.py
@@ -42,7 +42,8 @@ class Git(LazyMixin):
of the command to stdout.
Set its value to 'full' to see details about the returned values.
"""
- __slots__ = ("_working_dir", "cat_file_all", "cat_file_header", "_version_info")
+ __slots__ = ("_working_dir", "cat_file_all", "cat_file_header", "_version_info",
+ "_git_options")
# CONFIGURATION
# The size in bytes read from stdout when copying git's output to another stream
@@ -217,7 +218,8 @@ class Git(LazyMixin):
.git directory in case of bare repositories."""
super(Git, self).__init__()
self._working_dir = working_dir
-
+ self._git_options = ()
+
# cached command slots
self.cat_file_header = None
self.cat_file_all = None
@@ -417,6 +419,21 @@ class Git(LazyMixin):
# END for each arg
return outlist
+ def __call__(self, **kwargs):
+ """Specify command line options to the git executable
+ for a subcommand call
+
+ :param kwargs:
+ is a dict of keyword arguments.
+ these arguments are passed as in _call_process
+ but will be passed to the git command rather than
+ the subcommand.
+
+ ``Examples``::
+ git(work_tree='/tmp').difftool()"""
+ self._git_options = self.transform_kwargs(**kwargs)
+ return self
+
def _call_process(self, method, *args, **kwargs):
"""Run the given git command with the specified arguments and return
the result as a String
@@ -455,7 +472,14 @@ class Git(LazyMixin):
args = opt_args + ext_args
def make_call():
- call = [self.GIT_PYTHON_GIT_EXECUTABLE, dashify(method)]
+ call = [self.GIT_PYTHON_GIT_EXECUTABLE]
+
+ # add the git options, the reset to empty
+ # to avoid side_effects
+ call.extend(self._git_options)
+ self._git_options = ()
+
+ call.extend([dashify(method)])
call.extend(args)
return call
#END utility to recreate call after changes