Fix 236148: Avoid triggering a pager in internal git commands.

BUG=236148

Review URL: https://chromiumcodereview.appspot.com/14104005

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@197872 0039d316-1c4b-4281-b951-d872f2087c98
experimental/szager/collated-output
bratell@opera.com 12 years ago
parent e0558e6502
commit f267b0e55c

@ -65,13 +65,14 @@ def RunCommand(args, error_ok=False, error_message=None, **kwargs):
def RunGit(args, **kwargs): def RunGit(args, **kwargs):
"""Returns stdout.""" """Returns stdout."""
return RunCommand(['git'] + args, **kwargs) return RunCommand(['git', '--no-pager'] + args, **kwargs)
def RunGitWithCode(args): def RunGitWithCode(args):
"""Returns return code and stdout.""" """Returns return code and stdout."""
try: try:
out, code = subprocess2.communicate(['git'] + args, stdout=subprocess2.PIPE) out, code = subprocess2.communicate(['git', '--no-pager'] + args,
stdout=subprocess2.PIPE)
return code, out[0] return code, out[0]
except ValueError: except ValueError:
# When the subprocess fails, it returns None. That triggers a ValueError # When the subprocess fails, it returns None. That triggers a ValueError
@ -228,7 +229,8 @@ def print_stats(similarity, find_copies, args):
similarity_options = ['-M%s' % similarity] similarity_options = ['-M%s' % similarity]
return subprocess2.call( return subprocess2.call(
['git', 'diff', '--no-ext-diff', '--stat'] + similarity_options + args, ['git', '--no-pager',
'diff', '--no-ext-diff', '--stat'] + similarity_options + args,
env=env) env=env)
@ -297,7 +299,7 @@ class Settings(object):
# We don't want to go through all of history, so read a line from the # We don't want to go through all of history, so read a line from the
# pipe at a time. # pipe at a time.
# The -100 is an arbitrary limit so we don't search forever. # The -100 is an arbitrary limit so we don't search forever.
cmd = ['git', 'log', '-100', '--pretty=medium'] cmd = ['git', '--no-pager', 'log', '-100', '--pretty=medium']
proc = subprocess2.Popen(cmd, stdout=subprocess2.PIPE) proc = subprocess2.Popen(cmd, stdout=subprocess2.PIPE)
url = None url = None
for line in proc.stdout: for line in proc.stdout:
@ -666,11 +668,13 @@ or verify this branch is set up to track another (via the --track argument to
if not self.GitSanityChecks(upstream_branch): if not self.GitSanityChecks(upstream_branch):
DieWithError('\nGit sanity check failure') DieWithError('\nGit sanity check failure')
root = RunCommand(['git', 'rev-parse', '--show-cdup']).strip() or '.' root = RunCommand(['git', '--no-pager', 'rev-parse', '--show-cdup']).strip()
if not root:
root = '.'
absroot = os.path.abspath(root) absroot = os.path.abspath(root)
# We use the sha1 of HEAD as a name of this change. # We use the sha1 of HEAD as a name of this change.
name = RunCommand(['git', 'rev-parse', 'HEAD']).strip() name = RunCommand(['git', '--no-pager', 'rev-parse', 'HEAD']).strip()
# Need to pass a relative path for msysgit. # Need to pass a relative path for msysgit.
try: try:
files = scm.GIT.CaptureStatus([root], '.', upstream_branch) files = scm.GIT.CaptureStatus([root], '.', upstream_branch)
@ -691,7 +695,8 @@ or verify this branch is set up to track another (via the --track argument to
# If the change was never uploaded, use the log messages of all commits # If the change was never uploaded, use the log messages of all commits
# up to the branch point, as git cl upload will prefill the description # up to the branch point, as git cl upload will prefill the description
# with these log messages. # with these log messages.
description = RunCommand(['git', 'log', '--pretty=format:%s%n%n%b', description = RunCommand(['git', '--no-pager',
'log', '--pretty=format:%s%n%n%b',
'%s...' % (upstream_branch)]).strip() '%s...' % (upstream_branch)]).strip()
if not author: if not author:
@ -1708,7 +1713,7 @@ def CMDpatch(parser, args):
# We use "git apply" to apply the patch instead of "patch" so that we can # We use "git apply" to apply the patch instead of "patch" so that we can
# pick up file adds. # pick up file adds.
# The --index flag means: also insert into the index (so we catch adds). # The --index flag means: also insert into the index (so we catch adds).
cmd = ['git', 'apply', '--index', '-p0'] cmd = ['git', '--no-pager', 'apply', '--index', '-p0']
if options.reject: if options.reject:
cmd.append('--reject') cmd.append('--reject')
try: try:
@ -1734,7 +1739,7 @@ def CMDrebase(parser, args):
# git svn dcommit. # git svn dcommit.
# It's the only command that doesn't use parser at all since we just defer # It's the only command that doesn't use parser at all since we just defer
# execution to git-svn. # execution to git-svn.
return subprocess2.call(['git', 'svn', 'rebase'] + args) return subprocess2.call(['git', '--no-pager', 'svn', 'rebase'] + args)
def GetTreeStatus(): def GetTreeStatus():

@ -99,7 +99,8 @@ class GIT(object):
@staticmethod @staticmethod
def Capture(args, cwd, **kwargs): def Capture(args, cwd, **kwargs):
return subprocess2.check_output( return subprocess2.check_output(
['git'] + args, cwd=cwd, stderr=subprocess2.PIPE, **kwargs) ['git', '--no-pager'] + args,
cwd=cwd, stderr=subprocess2.PIPE, **kwargs)
@staticmethod @staticmethod
def CaptureStatus(files, cwd, upstream_branch): def CaptureStatus(files, cwd, upstream_branch):

@ -117,73 +117,83 @@ class TestGitCl(TestCase):
def _git_base_calls(cls, similarity, find_copies): def _git_base_calls(cls, similarity, find_copies):
if similarity is None: if similarity is None:
similarity = '50' similarity = '50'
similarity_call = ((['git', 'config', '--int', '--get', similarity_call = ((['git', '--no-pager', 'config', '--int', '--get',
'branch.master.git-cl-similarity'],), '') 'branch.master.git-cl-similarity'],), '')
else: else:
similarity_call = ((['git', 'config', '--int', similarity_call = ((['git', '--no-pager', 'config', '--int',
'branch.master.git-cl-similarity', similarity],), '') 'branch.master.git-cl-similarity', similarity],), '')
if find_copies is None: if find_copies is None:
find_copies = True find_copies = True
find_copies_call = ((['git', 'config', '--int', '--get', find_copies_call = ((['git', '--no-pager', 'config', '--int', '--get',
'branch.master.git-find-copies'],), '') 'branch.master.git-find-copies'],), '')
else: else:
val = str(int(find_copies)) val = str(int(find_copies))
find_copies_call = ((['git', 'config', '--int', find_copies_call = ((['git', '--no-pager', 'config', '--int',
'branch.master.git-find-copies', val],), '') 'branch.master.git-find-copies', val],), '')
if find_copies: if find_copies:
stat_call = ((['git', 'diff', '--no-ext-diff', '--stat', stat_call = ((['git', '--no-pager', 'diff', '--no-ext-diff', '--stat',
'--find-copies-harder', '-l100000', '-C'+similarity, '--find-copies-harder', '-l100000', '-C'+similarity,
'fake_ancestor_sha', 'HEAD'],), '+dat') 'fake_ancestor_sha', 'HEAD'],), '+dat')
else: else:
stat_call = ((['git', 'diff', '--no-ext-diff', '--stat', stat_call = ((['git', '--no-pager', 'diff', '--no-ext-diff', '--stat',
'-M'+similarity, 'fake_ancestor_sha', 'HEAD'],), '+dat') '-M'+similarity, 'fake_ancestor_sha', 'HEAD'],), '+dat')
return [ return [
((['git', 'config', 'rietveld.server'],), 'codereview.example.com'), ((['git', '--no-pager', 'config', 'rietveld.server'],),
((['git', 'symbolic-ref', 'HEAD'],), 'master'), 'codereview.example.com'),
((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'master'),
similarity_call, similarity_call,
((['git', 'symbolic-ref', 'HEAD'],), 'master'), ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'master'),
find_copies_call, find_copies_call,
((['git', 'update-index', '--refresh', '-q'],), ''), ((['git', '--no-pager', 'update-index', '--refresh', '-q'],), ''),
((['git', 'diff-index', '--name-status', 'HEAD'],), ''), ((['git', '--no-pager', 'diff-index', '--name-status', 'HEAD'],), ''),
((['git', 'symbolic-ref', 'HEAD'],), 'master'), ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'master'),
((['git', 'config', 'branch.master.merge'],), 'master'), ((['git', '--no-pager', 'config', 'branch.master.merge'],), 'master'),
((['git', 'config', 'branch.master.remote'],), 'origin'), ((['git', '--no-pager', 'config', 'branch.master.remote'],), 'origin'),
((['git', 'merge-base', 'master', 'HEAD'],), 'fake_ancestor_sha'), ((['git', '--no-pager', 'merge-base', 'master', 'HEAD'],),
'fake_ancestor_sha'),
] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [
((['git', 'rev-parse', '--show-cdup'],), ''), ((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''),
((['git', 'rev-parse', 'HEAD'],), '12345'), ((['git', '--no-pager', 'rev-parse', 'HEAD'],), '12345'),
((['git', 'diff', '--name-status', '-r', 'fake_ancestor_sha...', '.'],), ((['git', '--no-pager', 'diff', '--name-status', '-r',
'fake_ancestor_sha...', '.'],),
'M\t.gitignore\n'), 'M\t.gitignore\n'),
((['git', 'config', 'branch.master.rietveldissue'],), ''), ((['git', '--no-pager', 'config', 'branch.master.rietveldissue'],), ''),
((['git', 'config', 'branch.master.rietveldpatchset'],), ''), ((['git', '--no-pager', 'config', 'branch.master.rietveldpatchset'],),
((['git', 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],), ''),
((['git', '--no-pager', 'log', '--pretty=format:%s%n%n%b',
'fake_ancestor_sha...'],),
'foo'), 'foo'),
((['git', 'config', 'user.email'],), 'me@example.com'), ((['git', '--no-pager', 'config', 'user.email'],), 'me@example.com'),
stat_call, stat_call,
((['git', 'config', 'gerrit.host'],), ''), ((['git', '--no-pager', 'config', 'gerrit.host'],), ''),
((['git', 'log', '--pretty=format:%s\n\n%b', 'fake_ancestor_sha..HEAD'],), ((['git', '--no-pager', 'log', '--pretty=format:%s\n\n%b',
'fake_ancestor_sha..HEAD'],),
'desc\n'), 'desc\n'),
] ]
@classmethod @classmethod
def _git_upload_calls(cls): def _git_upload_calls(cls):
return [ return [
((['git', 'config', 'rietveld.cc'],), ''), ((['git', '--no-pager', 'config', 'rietveld.cc'],), ''),
((['git', 'config', 'branch.master.base-url'],), ''), ((['git', '--no-pager', 'config', 'branch.master.base-url'],), ''),
((['git', 'config', '--local', '--get-regexp', '^svn-remote\\.'],), ((['git', '--no-pager',
'config', '--local', '--get-regexp', '^svn-remote\\.'],),
(('', None), 0)), (('', None), 0)),
((['git', 'rev-parse', '--show-cdup'],), ''), ((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''),
((['git', 'svn', 'info'],), ''), ((['git', '--no-pager', 'svn', 'info'],), ''),
((['git', 'config', 'branch.master.rietveldissue', '1'],), ''), ((['git', '--no-pager',
((['git', 'config', 'branch.master.rietveldserver', 'config', 'branch.master.rietveldissue', '1'],), ''),
((['git', '--no-pager', 'config', 'branch.master.rietveldserver',
'https://codereview.example.com'],), ''), 'https://codereview.example.com'],), ''),
((['git', 'config', 'branch.master.rietveldpatchset', '2'],), ''), ((['git', '--no-pager',
((['git', 'rev-parse', 'HEAD'],), 'hash'), 'config', 'branch.master.rietveldpatchset', '2'],), ''),
((['git', 'symbolic-ref', 'HEAD'],), 'hash'), ((['git', '--no-pager', 'rev-parse', 'HEAD'],), 'hash'),
((['git', 'config', 'branch.hash.last-upload-hash', 'hash'],), ''), ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'hash'),
((['git', '--no-pager',
'config', 'branch.hash.last-upload-hash', 'hash'],), ''),
] ]
@staticmethod @staticmethod
@ -192,75 +202,91 @@ class TestGitCl(TestCase):
fake_cl = 'fake_cl_for_patch' fake_cl = 'fake_cl_for_patch'
return [ return [
# Calls to verify branch point is ancestor # Calls to verify branch point is ancestor
((['git', 'rev-parse', '--verify', diff_base],), fake_ancestor), ((['git', '--no-pager',
((['git', 'merge-base', fake_ancestor, 'HEAD'],), fake_ancestor), 'rev-parse', '--verify', diff_base],), fake_ancestor),
((['git', 'rev-list', '^' + fake_ancestor, 'HEAD'],), fake_cl), ((['git', '--no-pager',
'merge-base', fake_ancestor, 'HEAD'],), fake_ancestor),
((['git', '--no-pager',
'rev-list', '^' + fake_ancestor, 'HEAD'],), fake_cl),
# Mock a config miss (error code 1) # Mock a config miss (error code 1)
((['git', 'config', 'gitcl.remotebranch'],), (('', None), 1)), ((['git', '--no-pager',
'config', 'gitcl.remotebranch'],), (('', None), 1)),
# Call to GetRemoteBranch() # Call to GetRemoteBranch()
((['git', 'config', 'branch.%s.merge' % working_branch],), ((['git', '--no-pager',
'config', 'branch.%s.merge' % working_branch],),
'refs/heads/master'), 'refs/heads/master'),
((['git', 'config', 'branch.%s.remote' % working_branch],), 'origin'), ((['git', '--no-pager',
((['git', 'rev-list', '^' + fake_ancestor, 'config', 'branch.%s.remote' % working_branch],), 'origin'),
((['git', '--no-pager', 'rev-list', '^' + fake_ancestor,
'refs/remotes/origin/master'],), ''), 'refs/remotes/origin/master'],), ''),
] ]
@classmethod @classmethod
def _dcommit_calls_1(cls): def _dcommit_calls_1(cls):
return [ return [
((['git', 'config', '--local', '--get-regexp', '^svn-remote\\.'],), ((['git', '--no-pager',
'config', '--local', '--get-regexp', '^svn-remote\\.'],),
((('svn-remote.svn.url svn://svn.chromium.org/chrome\n' ((('svn-remote.svn.url svn://svn.chromium.org/chrome\n'
'svn-remote.svn.fetch trunk/src:refs/remotes/origin/master'), 'svn-remote.svn.fetch trunk/src:refs/remotes/origin/master'),
None), None),
0)), 0)),
((['git', 'config', 'rietveld.server'],), 'codereview.example.com'), ((['git', '--no-pager',
((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), 'config', 'rietveld.server'],), 'codereview.example.com'),
((['git', 'config', '--int', '--get', ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'),
((['git', '--no-pager', 'config', '--int', '--get',
'branch.working.git-cl-similarity'],), ''), 'branch.working.git-cl-similarity'],), ''),
((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'),
((['git', 'config', '--int', '--get', ((['git', '--no-pager', 'config', '--int', '--get',
'branch.working.git-find-copies'],), ''), 'branch.working.git-find-copies'],), ''),
((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'),
((['git', 'config', 'branch.working.merge'],), 'refs/heads/master'), ((['git', '--no-pager',
((['git', 'config', 'branch.working.remote'],), 'origin'), 'config', 'branch.working.merge'],), 'refs/heads/master'),
((['git', 'rev-list', '--merges', ((['git', '--no-pager', 'config', 'branch.working.remote'],), 'origin'),
((['git', '--no-pager', 'rev-list', '--merges',
'--grep=^SVN changes up to revision [0-9]*$', '--grep=^SVN changes up to revision [0-9]*$',
'refs/remotes/origin/master^!'],), ''), 'refs/remotes/origin/master^!'],), ''),
((['git', 'update-index', '--refresh', '-q'],), ''), ((['git', '--no-pager', 'update-index', '--refresh', '-q'],), ''),
((['git', 'diff-index', '--name-status', 'HEAD'],), ''), ((['git', '--no-pager', 'diff-index', '--name-status', 'HEAD'],), ''),
((['git', 'rev-list', '^refs/heads/working', ((['git', '--no-pager', 'rev-list', '^refs/heads/working',
'refs/remotes/origin/master'],), 'refs/remotes/origin/master'],),
''), ''),
((['git', 'log', '--grep=^git-svn-id:', '-1', '--pretty=format:%H'],), ((['git', '--no-pager',
'log', '--grep=^git-svn-id:', '-1', '--pretty=format:%H'],),
'3fc18b62c4966193eb435baabe2d18a3810ec82e'), '3fc18b62c4966193eb435baabe2d18a3810ec82e'),
((['git', 'rev-list', '^3fc18b62c4966193eb435baabe2d18a3810ec82e', ((['git', '--no-pager',
'rev-list', '^3fc18b62c4966193eb435baabe2d18a3810ec82e',
'refs/remotes/origin/master'],), ''), 'refs/remotes/origin/master'],), ''),
((['git', 'merge-base', 'refs/remotes/origin/master', 'HEAD'],), ((['git', '--no-pager',
'merge-base', 'refs/remotes/origin/master', 'HEAD'],),
'fake_ancestor_sha'), 'fake_ancestor_sha'),
] ]
@classmethod @classmethod
def _dcommit_calls_normal(cls): def _dcommit_calls_normal(cls):
return [ return [
((['git', 'rev-parse', '--show-cdup'],), ''), ((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''),
((['git', 'rev-parse', 'HEAD'],), ((['git', '--no-pager', 'rev-parse', 'HEAD'],),
'00ff397798ea57439712ed7e04ab96e13969ef40'), '00ff397798ea57439712ed7e04ab96e13969ef40'),
((['git', 'diff', '--name-status', '-r', 'fake_ancestor_sha...', ((['git', '--no-pager',
'diff', '--name-status', '-r', 'fake_ancestor_sha...',
'.'],), '.'],),
'M\tPRESUBMIT.py'), 'M\tPRESUBMIT.py'),
((['git', 'config', 'branch.working.rietveldissue'],), '12345'), ((['git', '--no-pager',
((['git', 'config', 'branch.working.rietveldpatchset'],), '31137'), 'config', 'branch.working.rietveldissue'],), '12345'),
((['git', 'config', 'branch.working.rietveldserver'],), ((['git', '--no-pager',
'config', 'branch.working.rietveldpatchset'],), '31137'),
((['git', '--no-pager', 'config', 'branch.working.rietveldserver'],),
'codereview.example.com'), 'codereview.example.com'),
((['git', 'config', 'user.email'],), 'author@example.com'), ((['git', '--no-pager', 'config', 'user.email'],), 'author@example.com'),
((['git', 'config', 'rietveld.tree-status-url'],), ''), ((['git', '--no-pager', 'config', 'rietveld.tree-status-url'],), ''),
] ]
@classmethod @classmethod
def _dcommit_calls_bypassed(cls): def _dcommit_calls_bypassed(cls):
return [ return [
((['git', 'config', 'branch.working.rietveldissue'],), '12345'), ((['git', '--no-pager',
((['git', 'config', 'branch.working.rietveldserver'],), 'config', 'branch.working.rietveldissue'],), '12345'),
((['git', '--no-pager', 'config', 'branch.working.rietveldserver'],),
'codereview.example.com'), 'codereview.example.com'),
(('GitClHooksBypassedCommit', (('GitClHooksBypassedCommit',
'Issue https://codereview.example.com/12345 bypassed hook when ' 'Issue https://codereview.example.com/12345 bypassed hook when '
@ -270,29 +296,31 @@ class TestGitCl(TestCase):
@classmethod @classmethod
def _dcommit_calls_3(cls): def _dcommit_calls_3(cls):
return [ return [
((['git', 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', ((['git', '--no-pager',
'diff', '--no-ext-diff', '--stat', '--find-copies-harder',
'-l100000', '-C50', 'fake_ancestor_sha', '-l100000', '-C50', 'fake_ancestor_sha',
'refs/heads/working'],), 'refs/heads/working'],),
(' PRESUBMIT.py | 2 +-\n' (' PRESUBMIT.py | 2 +-\n'
' 1 files changed, 1 insertions(+), 1 deletions(-)\n')), ' 1 files changed, 1 insertions(+), 1 deletions(-)\n')),
(('About to commit; enter to confirm.',), None), (('About to commit; enter to confirm.',), None),
((['git', 'show-ref', '--quiet', '--verify', ((['git', '--no-pager', 'show-ref', '--quiet', '--verify',
'refs/heads/git-cl-commit'],), 'refs/heads/git-cl-commit'],),
(('', None), 0)), (('', None), 0)),
((['git', 'branch', '-D', 'git-cl-commit'],), ''), ((['git', '--no-pager', 'branch', '-D', 'git-cl-commit'],), ''),
((['git', 'show-ref', '--quiet', '--verify', ((['git', '--no-pager', 'show-ref', '--quiet', '--verify',
'refs/heads/git-cl-cherry-pick'],), ''), 'refs/heads/git-cl-cherry-pick'],), ''),
((['git', 'rev-parse', '--show-cdup'],), '\n'), ((['git', '--no-pager', 'rev-parse', '--show-cdup'],), '\n'),
((['git', 'checkout', '-q', '-b', 'git-cl-commit'],), ''), ((['git', '--no-pager', 'checkout', '-q', '-b', 'git-cl-commit'],), ''),
((['git', 'reset', '--soft', 'fake_ancestor_sha'],), ''), ((['git', '--no-pager', 'reset', '--soft', 'fake_ancestor_sha'],), ''),
((['git', 'commit', '-m', ((['git', '--no-pager', 'commit', '-m',
'Issue: 12345\n\nR=john@chromium.org\n\n' 'Issue: 12345\n\nR=john@chromium.org\n\n'
'Review URL: https://codereview.example.com/12345'],), 'Review URL: https://codereview.example.com/12345'],),
''), ''),
((['git', 'svn', 'dcommit', '-C50', '--no-rebase', '--rmdir'],), ((['git', '--no-pager',
'svn', 'dcommit', '-C50', '--no-rebase', '--rmdir'],),
(('', None), 0)), (('', None), 0)),
((['git', 'checkout', '-q', 'working'],), ''), ((['git', '--no-pager', 'checkout', '-q', 'working'],), ''),
((['git', 'branch', '-D', 'git-cl-commit'],), ''), ((['git', '--no-pager', 'branch', '-D', 'git-cl-commit'],), ''),
] ]
@staticmethod @staticmethod
@ -452,30 +480,36 @@ class TestGitCl(TestCase):
@classmethod @classmethod
def _gerrit_base_calls(cls): def _gerrit_base_calls(cls):
return [ return [
((['git', 'config', 'rietveld.server'],), 'codereview.example.com'), ((['git', '--no-pager',
((['git', 'symbolic-ref', 'HEAD'],), 'master'), 'config', 'rietveld.server'],), 'codereview.example.com'),
((['git', 'config', '--int', '--get', ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'master'),
((['git', '--no-pager', 'config', '--int', '--get',
'branch.master.git-cl-similarity'],), ''), 'branch.master.git-cl-similarity'],), ''),
((['git', 'symbolic-ref', 'HEAD'],), 'master'), ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'master'),
((['git', 'config', '--int', '--get', ((['git', '--no-pager', 'config', '--int', '--get',
'branch.master.git-find-copies'],), ''), 'branch.master.git-find-copies'],), ''),
((['git', 'update-index', '--refresh', '-q'],), ''), ((['git', '--no-pager', 'update-index', '--refresh', '-q'],), ''),
((['git', 'diff-index', '--name-status', 'HEAD'],), ''), ((['git', '--no-pager', 'diff-index', '--name-status', 'HEAD'],), ''),
((['git', 'symbolic-ref', 'HEAD'],), 'master'), ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'master'),
((['git', 'config', 'branch.master.merge'],), 'master'), ((['git', '--no-pager', 'config', 'branch.master.merge'],), 'master'),
((['git', 'config', 'branch.master.remote'],), 'origin'), ((['git', '--no-pager', 'config', 'branch.master.remote'],), 'origin'),
((['git', 'merge-base', 'master', 'HEAD'],), 'fake_ancestor_sha'), ((['git', '--no-pager',
'merge-base', 'master', 'HEAD'],), 'fake_ancestor_sha'),
] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [
((['git', 'rev-parse', '--show-cdup'],), ''), ((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''),
((['git', 'rev-parse', 'HEAD'],), '12345'), ((['git', '--no-pager', 'rev-parse', 'HEAD'],), '12345'),
((['git', 'diff', '--name-status', '-r', 'fake_ancestor_sha...', '.'],), ((['git', '--no-pager',
'diff', '--name-status', '-r', 'fake_ancestor_sha...', '.'],),
'M\t.gitignore\n'), 'M\t.gitignore\n'),
((['git', 'config', 'branch.master.rietveldissue'],), ''), ((['git', '--no-pager', 'config', 'branch.master.rietveldissue'],), ''),
((['git', 'config', 'branch.master.rietveldpatchset'],), ''), ((['git', '--no-pager',
((['git', 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],), 'config', 'branch.master.rietveldpatchset'],), ''),
((['git', '--no-pager',
'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],),
'foo'), 'foo'),
((['git', 'config', 'user.email'],), 'me@example.com'), ((['git', '--no-pager', 'config', 'user.email'],), 'me@example.com'),
((['git', 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', ((['git', '--no-pager',
'diff', '--no-ext-diff', '--stat', '--find-copies-harder',
'-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],), '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],),
'+dat'), '+dat'),
] ]
@ -483,24 +517,25 @@ class TestGitCl(TestCase):
@staticmethod @staticmethod
def _gerrit_upload_calls(description, reviewers): def _gerrit_upload_calls(description, reviewers):
calls = [ calls = [
((['git', 'config', 'gerrit.host'],), 'gerrit.example.com'), ((['git', '--no-pager', 'config', 'gerrit.host'],),
((['git', 'log', '--pretty=format:%s\n\n%b', 'gerrit.example.com'),
((['git', '--no-pager', 'log', '--pretty=format:%s\n\n%b',
'fake_ancestor_sha..HEAD'],), 'fake_ancestor_sha..HEAD'],),
description) description)
] ]
if git_cl.CHANGE_ID not in description: if git_cl.CHANGE_ID not in description:
calls += [ calls += [
((['git', 'log', '--pretty=format:%s\n\n%b', ((['git', '--no-pager', 'log', '--pretty=format:%s\n\n%b',
'fake_ancestor_sha..HEAD'],), 'fake_ancestor_sha..HEAD'],),
description), description),
((['git', 'commit', '--amend', '-m', description],), ((['git', '--no-pager', 'commit', '--amend', '-m', description],),
''), ''),
((['git', 'log', '--pretty=format:%s\n\n%b', ((['git', '--no-pager', 'log', '--pretty=format:%s\n\n%b',
'fake_ancestor_sha..HEAD'],), 'fake_ancestor_sha..HEAD'],),
description) description)
] ]
calls += [ calls += [
((['git', 'config', 'rietveld.cc'],), '') ((['git', '--no-pager', 'config', 'rietveld.cc'],), '')
] ]
receive_pack = '--receive-pack=git receive-pack ' receive_pack = '--receive-pack=git receive-pack '
receive_pack += '--cc=joe@example.com' # from watch list receive_pack += '--cc=joe@example.com' # from watch list
@ -510,7 +545,8 @@ class TestGitCl(TestCase):
'--reviewer=' + email for email in sorted(reviewers)) '--reviewer=' + email for email in sorted(reviewers))
receive_pack += '' receive_pack += ''
calls += [ calls += [
((['git', 'push', receive_pack, 'origin', 'HEAD:refs/for/master'],), ((['git', '--no-pager',
'push', receive_pack, 'origin', 'HEAD:refs/for/master'],),
'') '')
] ]
return calls return calls
@ -578,29 +614,36 @@ class TestGitCl(TestCase):
self.mock(git_cl.os.path, 'exists', Exists) self.mock(git_cl.os.path, 'exists', Exists)
self.mock(git_cl, 'urlretrieve', self._mocked_call) self.mock(git_cl, 'urlretrieve', self._mocked_call)
self.calls = [ self.calls = [
((['git', 'config', 'rietveld.server', 'gerrit.chromium.org'],), ''), ((['git', '--no-pager', 'config', 'rietveld.server',
((['git', 'config', '--unset-all', 'rietveld.cc'],), ''), 'gerrit.chromium.org'],), ''),
((['git', 'config', '--unset-all', 'rietveld.tree-status-url'],), ''), ((['git', '--no-pager', 'config', '--unset-all', 'rietveld.cc'],), ''),
((['git', 'config', '--unset-all', 'rietveld.viewvc-url'],), ''), ((['git', '--no-pager', 'config', '--unset-all',
((['git', 'config', 'gerrit.host', 'gerrit.chromium.org'],), ''), 'rietveld.tree-status-url'],), ''),
((['git', 'config', 'gerrit.port', '29418'],), ''), ((['git', '--no-pager', 'config', '--unset-all',
'rietveld.viewvc-url'],), ''),
((['git', '--no-pager', 'config', 'gerrit.host',
'gerrit.chromium.org'],), ''),
((['git', '--no-pager', 'config', 'gerrit.port', '29418'],), ''),
# DownloadHooks(False) # DownloadHooks(False)
((['git', 'config', 'gerrit.host'],), 'gerrit.chromium.org'), ((['git', '--no-pager', 'config', 'gerrit.host'],),
((['git', 'config', 'rietveld.server'],), 'gerrit.chromium.org'), 'gerrit.chromium.org'),
((['git', 'rev-parse', '--show-cdup'],), ''), ((['git', '--no-pager', 'config', 'rietveld.server'],),
'gerrit.chromium.org'),
((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''),
((commit_msg_path, os.X_OK,), False), ((commit_msg_path, os.X_OK,), False),
(('https://gerrit.chromium.org/tools/hooks/commit-msg', (('https://gerrit.chromium.org/tools/hooks/commit-msg',
commit_msg_path,), ''), commit_msg_path,), ''),
((commit_msg_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR,), ''), ((commit_msg_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR,), ''),
# GetCodereviewSettingsInteractively # GetCodereviewSettingsInteractively
((['git', 'config', 'rietveld.server'],), 'gerrit.chromium.org'), ((['git', '--no-pager', 'config', 'rietveld.server'],),
'gerrit.chromium.org'),
(('Rietveld server (host[:port]) [https://gerrit.chromium.org]:',), (('Rietveld server (host[:port]) [https://gerrit.chromium.org]:',),
''), ''),
((['git', 'config', 'rietveld.cc'],), ''), ((['git', '--no-pager', 'config', 'rietveld.cc'],), ''),
(('CC list:',), ''), (('CC list:',), ''),
((['git', 'config', 'rietveld.tree-status-url'],), ''), ((['git', '--no-pager', 'config', 'rietveld.tree-status-url'],), ''),
(('Tree status URL:',), ''), (('Tree status URL:',), ''),
((['git', 'config', 'rietveld.viewvc-url'],), ''), ((['git', '--no-pager', 'config', 'rietveld.viewvc-url'],), ''),
(('ViewVC URL:',), ''), (('ViewVC URL:',), ''),
# DownloadHooks(True) # DownloadHooks(True)
((commit_msg_path, os.X_OK,), True), ((commit_msg_path, os.X_OK,), True),

Loading…
Cancel
Save