project: Require git >= 1.7.2 for setting config on command line

This option causes the git call to fail, which probably indicates a
programming error; callers should check the git version and change the
call appropriately if -c is not available. Failing loudly is preferable
to failing silently in the general case.

For an example of correctly checking at the call site, see I8fd313dd.
If callers prefer to fail silently, they may set GIT_CONFIG_PARAMETERS
in the environment rather than using the config kwarg to pass
configuration.

Change-Id: I0de18153d44d3225cd3031e6ead54461430ed334
This commit is contained in:
Dave Borowitz 2012-10-31 12:27:27 -07:00
parent e21526754b
commit b42b4746af

View File

@ -25,7 +25,7 @@ import sys
import time import time
from color import Coloring from color import Coloring
from git_command import GitCommand from git_command import GitCommand, git_require
from git_config import GitConfig, IsId, GetSchemeFromUrl, ID_RE from git_config import GitConfig, IsId, GetSchemeFromUrl, ID_RE
from error import GitError, HookError, UploadError from error import GitError, HookError, UploadError
from error import ManifestInvalidRevisionError from error import ManifestInvalidRevisionError
@ -1987,6 +1987,9 @@ class Project(object):
raise TypeError('%s() got an unexpected keyword argument %r' raise TypeError('%s() got an unexpected keyword argument %r'
% (name, k)) % (name, k))
if config is not None: if config is not None:
if not git_require((1, 7, 2)):
raise ValueError('cannot set config on command line for %s()'
% name)
for k, v in config.iteritems(): for k, v in config.iteritems():
cmdv.append('-c') cmdv.append('-c')
cmdv.append('%s=%s' % (k, v)) cmdv.append('%s=%s' % (k, v))