Skip to content

Commit 5b4f92c

Browse files
committed
Allow for setting git options, that are persistent across subcommand calls
1 parent 9e4a454 commit 5b4f92c

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

git/cmd.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class Git(LazyMixin):
161161
Set its value to 'full' to see details about the returned values.
162162
"""
163163
__slots__ = ("_working_dir", "cat_file_all", "cat_file_header", "_version_info",
164-
"_git_options", "_environment")
164+
"_git_options", "_persistent_git_options", "_environment")
165165

166166
_excluded_ = ('cat_file_all', 'cat_file_header', '_version_info')
167167

@@ -386,6 +386,7 @@ def __init__(self, working_dir=None):
386386
super(Git, self).__init__()
387387
self._working_dir = working_dir
388388
self._git_options = ()
389+
self._persistent_git_options = []
389390

390391
# Extra environment variables to pass to git commands
391392
self._environment = {}
@@ -402,6 +403,20 @@ def __getattr__(self, name):
402403
return LazyMixin.__getattr__(self, name)
403404
return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
404405

406+
def set_persistent_git_options(self, **kwargs):
407+
"""Specify command line options to the git executable
408+
for subsequent subcommand calls
409+
410+
:param kwargs:
411+
is a dict of keyword arguments.
412+
these arguments are passed as in _call_process
413+
but will be passed to the git command rather than
414+
the subcommand.
415+
"""
416+
417+
self._persistent_git_options = self.transform_kwargs(
418+
split_single_char_options=True, **kwargs)
419+
405420
def _set_cache_(self, attr):
406421
if attr == '_version_info':
407422
# We only use the first 4 numbers, as everthing else could be strings in fact (on windows)
@@ -820,7 +835,10 @@ def _call_process(self, method, *args, **kwargs):
820835

821836
call = [self.GIT_PYTHON_GIT_EXECUTABLE]
822837

823-
# add the git options, the reset to empty
838+
# add persistent git options
839+
call.extend(self._persistent_git_options)
840+
841+
# add the git options, then reset to empty
824842
# to avoid side_effects
825843
call.extend(self._git_options)
826844
self._git_options = ()

0 commit comments

Comments
 (0)