diff options
| author | Shawn Pearce <sop@google.com> | 2012-10-25 17:36:03 -0700 |
|---|---|---|
| committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2012-10-25 17:36:04 -0700 |
| commit | dc96476af37558c8eaf6d25087d4a604612642dd (patch) | |
| tree | dfdfde22a3ba610bdba5764a184ada1c3996e23e | |
| parent | 2577cec0952899040cd8c6523f69ece4cdc005ac (diff) | |
| parent | 091f893625269fd12adadf7d1f60c21b4b83e779 (diff) | |
| download | git-repo-dc96476af37558c8eaf6d25087d4a604612642dd.tar.gz | |
Merge "project: Support config args in git command callables"
| -rw-r--r-- | project.py | 17 |
1 files changed, 14 insertions, 3 deletions
| @@ -2146,7 +2146,9 @@ class Project(object): | |||
| 2146 | 2146 | ||
| 2147 | Since we don't have a 'rev_parse' method defined, the __getattr__ will | 2147 | Since we don't have a 'rev_parse' method defined, the __getattr__ will |
| 2148 | run. We'll replace the '_' with a '-' and try to run a git command. | 2148 | run. We'll replace the '_' with a '-' and try to run a git command. |
| 2149 | Any other arguments will be passed to the git command. | 2149 | Any other positional arguments will be passed to the git command, and the |
| 2150 | following keyword arguments are supported: | ||
| 2151 | config: An optional dict of git config options to be passed with '-c'. | ||
| 2150 | 2152 | ||
| 2151 | Args: | 2153 | Args: |
| 2152 | name: The name of the git command to call. Any '_' characters will | 2154 | name: The name of the git command to call. Any '_' characters will |
| @@ -2156,8 +2158,17 @@ class Project(object): | |||
| 2156 | A callable object that will try to call git with the named command. | 2158 | A callable object that will try to call git with the named command. |
| 2157 | """ | 2159 | """ |
| 2158 | name = name.replace('_', '-') | 2160 | name = name.replace('_', '-') |
| 2159 | def runner(*args): | 2161 | def runner(*args, **kwargs): |
| 2160 | cmdv = [name] | 2162 | cmdv = [] |
| 2163 | config = kwargs.pop('config', None) | ||
| 2164 | for k in kwargs: | ||
| 2165 | raise TypeError('%s() got an unexpected keyword argument %r' | ||
| 2166 | % (name, k)) | ||
| 2167 | if config is not None: | ||
| 2168 | for k, v in config.iteritems(): | ||
| 2169 | cmdv.append('-c') | ||
| 2170 | cmdv.append('%s=%s' % (k, v)) | ||
| 2171 | cmdv.append(name) | ||
| 2161 | cmdv.extend(args) | 2172 | cmdv.extend(args) |
| 2162 | p = GitCommand(self._project, | 2173 | p = GitCommand(self._project, |
| 2163 | cmdv, | 2174 | cmdv, |
