Eliminate all interactive terminal prompts from git.

BUG=

Review URL: https://codereview.chromium.org/247493002

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@265735 0039d316-1c4b-4281-b951-d872f2087c98
changes/01/332501/1
szager@chromium.org 11 years ago
parent a2aec97d74
commit 6d8115d009

@ -962,7 +962,8 @@ class GitWrapper(SCMWrapper):
def _Capture(self, args, **kwargs):
kwargs.setdefault('cwd', self.checkout_path)
kwargs.setdefault('stderr', subprocess2.PIPE)
return subprocess2.check_output(['git'] + args, **kwargs).strip()
env = scm.GIT.ApplyEnvVars(kwargs)
return subprocess2.check_output(['git'] + args, env=env, **kwargs).strip()
def _UpdateBranchHeads(self, options, fetch=False):
"""Adds, and optionally fetches, "branch-heads" refspecs if requested."""
@ -983,22 +984,11 @@ class GitWrapper(SCMWrapper):
kwargs.setdefault('stdout', self.out_fh)
kwargs['filter_fn'] = self.filter
kwargs.setdefault('print_stdout', False)
# Don't prompt for passwords; just fail quickly and noisily.
# By default, git will use an interactive terminal prompt when a username/
# password is needed. That shouldn't happen in the chromium workflow,
# and if it does, then gclient may hide the prompt in the midst of a flood
# of terminal spew. The only indication that something has gone wrong
# will be when gclient hangs unresponsively. Instead, we disable the
# password prompt and simply allow git to fail noisily. The error
# message produced by git will be copied to gclient's output.
env = kwargs.get('env') or kwargs.setdefault('env', os.environ.copy())
env.setdefault('GIT_ASKPASS', 'true')
env.setdefault('SSH_ASKPASS', 'true')
env = scm.GIT.ApplyEnvVars(kwargs)
cmd = ['git'] + args
header = "running '%s' in '%s'" % (' '.join(cmd), cwd)
self.filter(header)
return gclient_utils.CheckCallAndFilter(cmd, **kwargs)
return gclient_utils.CheckCallAndFilter(cmd, env=env, **kwargs)
class SVNWrapper(SCMWrapper):

@ -97,10 +97,25 @@ class GIT(object):
current_version = None
@staticmethod
def Capture(args, cwd, strip_out=True, **kwargs):
env = os.environ.copy()
def ApplyEnvVars(kwargs):
env = kwargs.pop('env', None) or os.environ.copy()
# Don't prompt for passwords; just fail quickly and noisily.
# By default, git will use an interactive terminal prompt when a username/
# password is needed. That shouldn't happen in the chromium workflow,
# and if it does, then gclient may hide the prompt in the midst of a flood
# of terminal spew. The only indication that something has gone wrong
# will be when gclient hangs unresponsively. Instead, we disable the
# password prompt and simply allow git to fail noisily. The error
# message produced by git will be copied to gclient's output.
env.setdefault('GIT_ASKPASS', 'true')
env.setdefault('SSH_ASKPASS', 'true')
# 'cat' is a magical git string that disables pagers on all platforms.
env['GIT_PAGER'] = 'cat'
env.setdefault('GIT_PAGER', 'cat')
return env
@staticmethod
def Capture(args, cwd, strip_out=True, **kwargs):
env = GIT.ApplyEnvVars(kwargs)
output = subprocess2.check_output(
['git'] + args,
cwd=cwd, stderr=subprocess2.PIPE, env=env, **kwargs)

@ -1308,13 +1308,13 @@ class ManagedGitWrapperTestCaseMox(BaseTestCase):
gclient_scm.GitWrapper._Clone('refs/remotes/origin/master', self.url,
options)
self.mox.StubOutWithMock(gclient_scm.subprocess2, 'check_output', True)
gclient_scm.subprocess2.check_output(['git', 'ls-files'],
cwd=self.base_path,
stderr=-1,
).AndReturn('')
gclient_scm.subprocess2.check_output(
['git', 'ls-files'], cwd=self.base_path,
env=gclient_scm.scm.GIT.ApplyEnvVars({}), stderr=-1,).AndReturn('')
gclient_scm.subprocess2.check_output(
['git', 'rev-parse', '--verify', 'HEAD'],
cwd=self.base_path,
env=gclient_scm.scm.GIT.ApplyEnvVars({}),
stderr=-1,
).AndReturn('')
@ -1342,13 +1342,13 @@ class ManagedGitWrapperTestCaseMox(BaseTestCase):
options)
# pylint: disable=E1120
self.mox.StubOutWithMock(gclient_scm.subprocess2, 'check_output', True)
gclient_scm.subprocess2.check_output(['git', 'ls-files'],
cwd=self.base_path,
stderr=-1,
).AndReturn('')
gclient_scm.subprocess2.check_output(
['git', 'ls-files'], cwd=self.base_path,
env=gclient_scm.scm.GIT.ApplyEnvVars({}), stderr=-1,).AndReturn('')
gclient_scm.subprocess2.check_output(
['git', 'rev-parse', '--verify', 'HEAD'],
cwd=self.base_path,
env=gclient_scm.scm.GIT.ApplyEnvVars({}),
stderr=-1,
).AndReturn('')

@ -73,6 +73,7 @@ class RootTestCase(BaseSCMTestCase):
class GitWrapperTestCase(BaseSCMTestCase):
def testMembersChanged(self):
members = [
'ApplyEnvVars',
'AssertVersion',
'Capture',
'CaptureStatus',

Loading…
Cancel
Save