diff options
author | Eric Brunson <brunson@brunson.com> | 2014-04-25 10:20:28 -0600 |
---|---|---|
committer | Eric Brunson <brunson@brunson.com> | 2014-04-25 10:20:28 -0600 |
commit | 811a6514571a94ed2e2704fb3a398218c739c9e9 (patch) | |
tree | 6ac71ddabb946f0dadb205876ffff650322aa423 /git/cmd.py | |
parent | e6a2942a982c2541a6b6f7c67aa7dbf57ed060ca (diff) | |
parent | f5ec638a77dd1cd38512bc9cf2ebae949e7a8812 (diff) | |
download | gitpython-811a6514571a94ed2e2704fb3a398218c739c9e9.tar.gz |
Merge pull request #154 from brunson/0.3
add git command options
Diffstat (limited to 'git/cmd.py')
-rw-r--r-- | git/cmd.py | 38 |
1 files changed, 33 insertions, 5 deletions
@@ -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 @@ -386,7 +388,7 @@ class Git(LazyMixin): else: return stdout_value - def transform_kwargs(self, **kwargs): + def transform_kwargs(self, split_single_char_options=False, **kwargs): """Transforms Python style kwargs into git command line options.""" args = list() for k, v in kwargs.items(): @@ -394,7 +396,10 @@ class Git(LazyMixin): if v is True: args.append("-%s" % k) elif type(v) is not bool: - args.append("-%s%s" % (k, v)) + if split_single_char_options: + args.extend(["-%s" % k, "%s" % v]) + else: + args.append("-%s%s" % (k, v)) else: if v is True: args.append("--%s" % dashify(k)) @@ -417,6 +422,22 @@ 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( + split_single_char_options=True, **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 +476,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 |