summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Borowitz <dborowitz@google.com>2012-10-23 17:01:04 -0700
committerDave Borowitz <dborowitz@google.com>2012-10-24 14:52:08 -0700
commit091f893625269fd12adadf7d1f60c21b4b83e779 (patch)
treebec3e027600f88a73108aa3c0f2f8f122903733d
parentd947858325ae70ff9c0b2f463a9e8c4ffd00002a (diff)
downloadgit-repo-091f893625269fd12adadf7d1f60c21b4b83e779.tar.gz
project: Support config args in git command callables
Change-Id: I9d4d0d2b1aeebe41a6b24a339a154d258af665eb
-rw-r--r--project.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/project.py b/project.py
index 472b1d32..099d0b5a 100644
--- a/project.py
+++ b/project.py
@@ -1969,7 +1969,9 @@ class Project(object):
1969 1969
1970 Since we don't have a 'rev_parse' method defined, the __getattr__ will 1970 Since we don't have a 'rev_parse' method defined, the __getattr__ will
1971 run. We'll replace the '_' with a '-' and try to run a git command. 1971 run. We'll replace the '_' with a '-' and try to run a git command.
1972 Any other arguments will be passed to the git command. 1972 Any other positional arguments will be passed to the git command, and the
1973 following keyword arguments are supported:
1974 config: An optional dict of git config options to be passed with '-c'.
1973 1975
1974 Args: 1976 Args:
1975 name: The name of the git command to call. Any '_' characters will 1977 name: The name of the git command to call. Any '_' characters will
@@ -1979,8 +1981,17 @@ class Project(object):
1979 A callable object that will try to call git with the named command. 1981 A callable object that will try to call git with the named command.
1980 """ 1982 """
1981 name = name.replace('_', '-') 1983 name = name.replace('_', '-')
1982 def runner(*args): 1984 def runner(*args, **kwargs):
1983 cmdv = [name] 1985 cmdv = []
1986 config = kwargs.pop('config', None)
1987 for k in kwargs:
1988 raise TypeError('%s() got an unexpected keyword argument %r'
1989 % (name, k))
1990 if config is not None:
1991 for k, v in config.iteritems():
1992 cmdv.append('-c')
1993 cmdv.append('%s=%s' % (k, v))
1994 cmdv.append(name)
1984 cmdv.extend(args) 1995 cmdv.extend(args)
1985 p = GitCommand(self._project, 1996 p = GitCommand(self._project,
1986 cmdv, 1997 cmdv,