Skip to content

Commit e0acb83

Browse files
committed
Added 'insert_kwargs_after' flag for consumption by _call_process.
While at it, all other invocations of .git in remote.py were reviewed Fixes gitpython-developers#262
1 parent bfcdf2b commit e0acb83

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

git/cmd.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,11 +753,23 @@ def _call_process(self, method, *args, **kwargs):
753753
except KeyError:
754754
pass
755755

756+
insert_after_this_arg = kwargs.pop('insert_kwargs_after', None)
757+
756758
# Prepare the argument list
757759
opt_args = self.transform_kwargs(**kwargs)
758760
ext_args = self.__unpack_args([a for a in args if a is not None])
759761

760-
args = opt_args + ext_args
762+
if insert_after_this_arg is None:
763+
args = opt_args + ext_args
764+
else:
765+
try:
766+
index = ext_args.index(insert_after_this_arg)
767+
except ValueError:
768+
raise ValueError("Couldn't find argument '%s' in args %s to insert kwargs after"
769+
% (insert_after_this_arg, str(ext_args)))
770+
# end handle error
771+
args = ext_args[:index + 1] + opt_args + ext_args[index + 1:]
772+
# end handle kwargs
761773

762774
def make_call():
763775
call = [self.GIT_PYTHON_GIT_EXECUTABLE]

git/remote.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,9 @@ def create(cls, repo, name, url, **kwargs):
477477
:param kwargs: Additional arguments to be passed to the git-remote add command
478478
:return: New Remote instance
479479
:raise GitCommandError: in case an origin with that name already exists"""
480-
repo.git.remote("add", name, url, **kwargs)
480+
scmd = 'add'
481+
kwargs['insert_kwargs_after'] = scmd
482+
repo.git.remote(scmd, name, url, **kwargs)
481483
return cls(repo, name)
482484

483485
# add is an alias
@@ -517,7 +519,9 @@ def update(self, **kwargs):
517519
Additional arguments passed to git-remote update
518520
519521
:return: self """
520-
self.repo.git.remote("update", self.name, **kwargs)
522+
scmd = 'update'
523+
kwargs['insert_kwargs_after'] = scmd
524+
self.repo.git.remote(scmd, self.name, **kwargs)
521525
return self
522526

523527
def _get_fetch_info_from_stderr(self, proc, progress):

git/test/test_git.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ def test_single_char_git_options_are_passed_to_git(self):
155155
def test_change_to_transform_kwargs_does_not_break_command_options(self):
156156
self.git.log(n=1)
157157

158+
def test_insert_after_kwarg_raises(self):
159+
# This isn't a complete add command, which doesn't matter here
160+
self.failUnlessRaises(ValueError, self.git.remote, 'add', insert_kwargs_after='foo')
161+
158162
def test_env_vars_passed_to_git(self):
159163
editor = 'non_existant_editor'
160164
with mock.patch.dict('os.environ', {'GIT_EDITOR': editor}):

git/test/test_remote.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,9 @@ def test_creation_and_removal(self, bare_rw_repo):
486486
# END if deleted remote matches existing remote's name
487487
# END for each remote
488488

489+
# Issue #262 - the next call would fail if bug wasn't fixed
490+
bare_rw_repo.create_remote('bogus', '/bogus/path', mirror='push')
491+
489492
def test_fetch_info(self):
490493
# assure we can handle remote-tracking branches
491494
fetch_info_line_fmt = "c437ee5deb8d00cf02f03720693e4c802e99f390 not-for-merge %s '0.3' of "

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy