diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2015-02-21 10:12:11 +0100 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2015-02-21 10:14:59 +0100 |
commit | e0acb8371bb2b68c2bda04db7cb2746ba3f9da86 (patch) | |
tree | dad907401197e27fee983e420cc780f48cd6a463 | |
parent | bfcdf2bef08f17b4726b67f06c84be3bfe2c39b8 (diff) | |
download | gitpython-e0acb8371bb2b68c2bda04db7cb2746ba3f9da86.tar.gz |
Added 'insert_kwargs_after' flag for consumption by _call_process.
While at it, all other invocations of .git in remote.py were reviewed
Fixes #262
-rw-r--r-- | git/cmd.py | 14 | ||||
-rw-r--r-- | git/remote.py | 8 | ||||
-rw-r--r-- | git/test/test_git.py | 4 | ||||
-rw-r--r-- | git/test/test_remote.py | 3 |
4 files changed, 26 insertions, 3 deletions
@@ -753,11 +753,23 @@ class Git(LazyMixin): except KeyError: pass + insert_after_this_arg = kwargs.pop('insert_kwargs_after', None) + # Prepare the argument list opt_args = self.transform_kwargs(**kwargs) ext_args = self.__unpack_args([a for a in args if a is not None]) - args = opt_args + ext_args + if insert_after_this_arg is None: + args = opt_args + ext_args + else: + try: + index = ext_args.index(insert_after_this_arg) + except ValueError: + raise ValueError("Couldn't find argument '%s' in args %s to insert kwargs after" + % (insert_after_this_arg, str(ext_args))) + # end handle error + args = ext_args[:index + 1] + opt_args + ext_args[index + 1:] + # end handle kwargs def make_call(): call = [self.GIT_PYTHON_GIT_EXECUTABLE] diff --git a/git/remote.py b/git/remote.py index 2267c203..8911aaa4 100644 --- a/git/remote.py +++ b/git/remote.py @@ -477,7 +477,9 @@ class Remote(LazyMixin, Iterable): :param kwargs: Additional arguments to be passed to the git-remote add command :return: New Remote instance :raise GitCommandError: in case an origin with that name already exists""" - repo.git.remote("add", name, url, **kwargs) + scmd = 'add' + kwargs['insert_kwargs_after'] = scmd + repo.git.remote(scmd, name, url, **kwargs) return cls(repo, name) # add is an alias @@ -517,7 +519,9 @@ class Remote(LazyMixin, Iterable): Additional arguments passed to git-remote update :return: self """ - self.repo.git.remote("update", self.name, **kwargs) + scmd = 'update' + kwargs['insert_kwargs_after'] = scmd + self.repo.git.remote(scmd, self.name, **kwargs) return self def _get_fetch_info_from_stderr(self, proc, progress): diff --git a/git/test/test_git.py b/git/test/test_git.py index 8087bc45..ef694755 100644 --- a/git/test/test_git.py +++ b/git/test/test_git.py @@ -155,6 +155,10 @@ class TestGit(TestBase): def test_change_to_transform_kwargs_does_not_break_command_options(self): self.git.log(n=1) + def test_insert_after_kwarg_raises(self): + # This isn't a complete add command, which doesn't matter here + self.failUnlessRaises(ValueError, self.git.remote, 'add', insert_kwargs_after='foo') + def test_env_vars_passed_to_git(self): editor = 'non_existant_editor' with mock.patch.dict('os.environ', {'GIT_EDITOR': editor}): diff --git a/git/test/test_remote.py b/git/test/test_remote.py index 2540e49b..8500a295 100644 --- a/git/test/test_remote.py +++ b/git/test/test_remote.py @@ -486,6 +486,9 @@ class TestRemote(TestBase): # END if deleted remote matches existing remote's name # END for each remote + # Issue #262 - the next call would fail if bug wasn't fixed + bare_rw_repo.create_remote('bogus', '/bogus/path', mirror='push') + def test_fetch_info(self): # assure we can handle remote-tracking branches fetch_info_line_fmt = "c437ee5deb8d00cf02f03720693e4c802e99f390 not-for-merge %s '0.3' of " |