summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Poldrack <benjaminpoldrack@gmail.com>2016-10-18 15:10:11 +0200
committerBenjamin Poldrack <benjaminpoldrack@gmail.com>2016-10-18 15:10:11 +0200
commit5b4f92c8eea41f20b95f9e62a39b210400f4d2a9 (patch)
tree06505761e6f75252716308f333499d4866f8bdc1
parent9e4a4545dd513204efb6afe40e4b50c3b5f77e50 (diff)
downloadgitpython-5b4f92c8eea41f20b95f9e62a39b210400f4d2a9.tar.gz
Allow for setting git options, that are persistent across subcommand calls
-rw-r--r--git/cmd.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/git/cmd.py b/git/cmd.py
index f0757301..3d455546 100644
--- a/git/cmd.py
+++ b/git/cmd.py
@@ -161,7 +161,7 @@ class Git(LazyMixin):
Set its value to 'full' to see details about the returned values.
"""
__slots__ = ("_working_dir", "cat_file_all", "cat_file_header", "_version_info",
- "_git_options", "_environment")
+ "_git_options", "_persistent_git_options", "_environment")
_excluded_ = ('cat_file_all', 'cat_file_header', '_version_info')
@@ -386,6 +386,7 @@ class Git(LazyMixin):
super(Git, self).__init__()
self._working_dir = working_dir
self._git_options = ()
+ self._persistent_git_options = []
# Extra environment variables to pass to git commands
self._environment = {}
@@ -402,6 +403,20 @@ class Git(LazyMixin):
return LazyMixin.__getattr__(self, name)
return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
+ def set_persistent_git_options(self, **kwargs):
+ """Specify command line options to the git executable
+ for subsequent subcommand calls
+
+ :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.
+ """
+
+ self._persistent_git_options = self.transform_kwargs(
+ split_single_char_options=True, **kwargs)
+
def _set_cache_(self, attr):
if attr == '_version_info':
# We only use the first 4 numbers, as everthing else could be strings in fact (on windows)
@@ -820,7 +835,10 @@ class Git(LazyMixin):
call = [self.GIT_PYTHON_GIT_EXECUTABLE]
- # add the git options, the reset to empty
+ # add persistent git options
+ call.extend(self._persistent_git_options)
+
+ # add the git options, then reset to empty
# to avoid side_effects
call.extend(self._git_options)
self._git_options = ()