Commit 82b91cd1 authored by bratell@opera.com's avatar bratell@opera.com

Replace --no-pager with GIT_PAGER=cat

--no-pager looks ugly in logs and output and makes commands harder to
read. Setting an environment variable is better.

This is a followup to https://chromiumcodereview.appspot.com/14104005/
which added --no-pager.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@210503 0039d316-1c4b-4281-b951-d872f2087c98
parent 224ba24f
...@@ -69,13 +69,17 @@ def RunCommand(args, error_ok=False, error_message=None, **kwargs): ...@@ -69,13 +69,17 @@ 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', '--no-pager'] + args, **kwargs) return RunCommand(['git'] + 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', '--no-pager'] + args, env = os.environ.copy()
# 'cat' is a magical git string that disables pagers on all platforms.
env['GIT_PAGER'] = 'cat'
out, code = subprocess2.communicate(['git'] + args,
env=env,
stdout=subprocess2.PIPE) stdout=subprocess2.PIPE)
return code, out[0] return code, out[0]
except ValueError: except ValueError:
...@@ -225,6 +229,8 @@ def print_stats(similarity, find_copies, args): ...@@ -225,6 +229,8 @@ def print_stats(similarity, find_copies, args):
env = os.environ.copy() env = os.environ.copy()
if 'GIT_EXTERNAL_DIFF' in env: if 'GIT_EXTERNAL_DIFF' in env:
del env['GIT_EXTERNAL_DIFF'] del env['GIT_EXTERNAL_DIFF']
# 'cat' is a magical git string that disables pagers on all platforms.
env['GIT_PAGER'] = 'cat'
if find_copies: if find_copies:
similarity_options = ['--find-copies-harder', '-l100000', similarity_options = ['--find-copies-harder', '-l100000',
...@@ -233,7 +239,7 @@ def print_stats(similarity, find_copies, args): ...@@ -233,7 +239,7 @@ def print_stats(similarity, find_copies, args):
similarity_options = ['-M%s' % similarity] similarity_options = ['-M%s' % similarity]
return subprocess2.call( return subprocess2.call(
['git', '--no-pager', ['git',
'diff', '--no-ext-diff', '--stat'] + similarity_options + args, 'diff', '--no-ext-diff', '--stat'] + similarity_options + args,
env=env) env=env)
...@@ -301,11 +307,15 @@ class Settings(object): ...@@ -301,11 +307,15 @@ class Settings(object):
# regexp matching the git-svn line that contains the URL. # regexp matching the git-svn line that contains the URL.
git_svn_re = re.compile(r'^\s*git-svn-id: (\S+)@', re.MULTILINE) git_svn_re = re.compile(r'^\s*git-svn-id: (\S+)@', re.MULTILINE)
env = os.environ.copy()
# 'cat' is a magical git string that disables pagers on all platforms.
env['GIT_PAGER'] = 'cat'
# 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', '--no-pager', 'log', '-100', '--pretty=medium'] cmd = ['git', 'log', '-100', '--pretty=medium']
proc = subprocess2.Popen(cmd, stdout=subprocess2.PIPE) proc = subprocess2.Popen(cmd, stdout=subprocess2.PIPE, env=env)
url = None url = None
for line in proc.stdout: for line in proc.stdout:
match = git_svn_re.match(line) match = git_svn_re.match(line)
...@@ -684,13 +694,17 @@ or verify this branch is set up to track another (via the --track argument to ...@@ -684,13 +694,17 @@ 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', '--no-pager', 'rev-parse', '--show-cdup']).strip() env = os.environ.copy()
# 'cat' is a magical git string that disables pagers on all platforms.
env['GIT_PAGER'] = 'cat'
root = RunCommand(['git', 'rev-parse', '--show-cdup'], env=env).strip()
if not root: if not root:
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', '--no-pager', 'rev-parse', 'HEAD']).strip() name = RunCommand(['git', 'rev-parse', 'HEAD'], env=env).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)
...@@ -711,9 +725,10 @@ or verify this branch is set up to track another (via the --track argument to ...@@ -711,9 +725,10 @@ 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', '--no-pager', description = RunCommand(['git',
'log', '--pretty=format:%s%n%n%b', 'log', '--pretty=format:%s%n%n%b',
'%s...' % (upstream_branch)]).strip() '%s...' % (upstream_branch)],
env=env).strip()
if not author: if not author:
author = RunGit(['config', 'user.email']).strip() or None author = RunGit(['config', 'user.email']).strip() or None
...@@ -1751,14 +1766,19 @@ def CMDpatch(parser, args): ...@@ -1751,14 +1766,19 @@ def CMDpatch(parser, args):
except subprocess2.CalledProcessError: except subprocess2.CalledProcessError:
DieWithError('Git patch mungling failed.') DieWithError('Git patch mungling failed.')
logging.info(patch_data) logging.info(patch_data)
env = os.environ.copy()
# 'cat' is a magical git string that disables pagers on all platforms.
env['GIT_PAGER'] = 'cat'
# 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', '--no-pager', 'apply', '--index', '-p0'] cmd = ['git', 'apply', '--index', '-p0']
if options.reject: if options.reject:
cmd.append('--reject') cmd.append('--reject')
try: try:
subprocess2.check_call(cmd, stdin=patch_data, stdout=subprocess2.VOID) subprocess2.check_call(cmd, env=env,
stdin=patch_data, stdout=subprocess2.VOID)
except subprocess2.CalledProcessError: except subprocess2.CalledProcessError:
DieWithError('Failed to apply the patch') DieWithError('Failed to apply the patch')
...@@ -1780,7 +1800,11 @@ def CMDrebase(parser, args): ...@@ -1780,7 +1800,11 @@ 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', '--no-pager', 'svn', 'rebase'] + args) env = os.environ.copy()
# 'cat' is a magical git string that disables pagers on all platforms.
env['GIT_PAGER'] = 'cat'
return subprocess2.call(['git', 'svn', 'rebase'] + args, env=env)
def GetTreeStatus(): def GetTreeStatus():
......
...@@ -98,9 +98,12 @@ class GIT(object): ...@@ -98,9 +98,12 @@ class GIT(object):
@staticmethod @staticmethod
def Capture(args, cwd, **kwargs): def Capture(args, cwd, **kwargs):
env = os.environ.copy()
# 'cat' is a magical git string that disables pagers on all platforms.
env['GIT_PAGER'] = 'cat'
return subprocess2.check_output( return subprocess2.check_output(
['git', '--no-pager'] + args, ['git'] + args,
cwd=cwd, stderr=subprocess2.PIPE, **kwargs).strip() cwd=cwd, stderr=subprocess2.PIPE, env=env, **kwargs).strip()
@staticmethod @staticmethod
def CaptureStatus(files, cwd, upstream_branch): def CaptureStatus(files, cwd, upstream_branch):
......
...@@ -122,59 +122,59 @@ class TestGitCl(TestCase): ...@@ -122,59 +122,59 @@ 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', '--no-pager', 'config', '--int', '--get', similarity_call = ((['git', 'config', '--int', '--get',
'branch.master.git-cl-similarity'],), '') 'branch.master.git-cl-similarity'],), '')
else: else:
similarity_call = ((['git', '--no-pager', 'config', '--int', similarity_call = ((['git', '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', '--no-pager', 'config', '--int', '--get', find_copies_call = ((['git', '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', '--no-pager', 'config', '--int', find_copies_call = ((['git', 'config', '--int',
'branch.master.git-find-copies', val],), '') 'branch.master.git-find-copies', val],), '')
if find_copies: if find_copies:
stat_call = ((['git', '--no-pager', 'diff', '--no-ext-diff', '--stat', stat_call = ((['git', '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', '--no-pager', 'diff', '--no-ext-diff', '--stat', stat_call = ((['git', 'diff', '--no-ext-diff', '--stat',
'-M'+similarity, 'fake_ancestor_sha', 'HEAD'],), '+dat') '-M'+similarity, 'fake_ancestor_sha', 'HEAD'],), '+dat')
return [ return [
((['git', '--no-pager', 'config', 'rietveld.server'],), ((['git', 'config', 'rietveld.server'],),
'codereview.example.com'), 'codereview.example.com'),
((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'master'), ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
similarity_call, similarity_call,
((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'master'), ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
find_copies_call, find_copies_call,
((['git', '--no-pager', 'update-index', '--refresh', '-q'],), ''), ((['git', 'update-index', '--refresh', '-q'],), ''),
((['git', '--no-pager', 'diff-index', '--name-status', 'HEAD'],), ''), ((['git', 'diff-index', '--name-status', 'HEAD'],), ''),
((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'master'), ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
((['git', '--no-pager', 'config', 'branch.master.merge'],), 'master'), ((['git', 'config', 'branch.master.merge'],), 'master'),
((['git', '--no-pager', 'config', 'branch.master.remote'],), 'origin'), ((['git', 'config', 'branch.master.remote'],), 'origin'),
((['git', '--no-pager', 'merge-base', 'master', 'HEAD'],), ((['git', 'merge-base', 'master', 'HEAD'],),
'fake_ancestor_sha'), 'fake_ancestor_sha'),
] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [
((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''), ((['git', 'rev-parse', '--show-cdup'],), ''),
((['git', '--no-pager', 'rev-parse', 'HEAD'],), '12345'), ((['git', 'rev-parse', 'HEAD'],), '12345'),
((['git', '--no-pager', 'diff', '--name-status', '--no-renames', '-r', ((['git', 'diff', '--name-status', '--no-renames', '-r',
'fake_ancestor_sha...', '.'],), 'fake_ancestor_sha...', '.'],),
'M\t.gitignore\n'), 'M\t.gitignore\n'),
((['git', '--no-pager', 'config', 'branch.master.rietveldissue'],), ''), ((['git', 'config', 'branch.master.rietveldissue'],), ''),
((['git', '--no-pager', 'config', 'branch.master.rietveldpatchset'],), ((['git', 'config', 'branch.master.rietveldpatchset'],),
''), ''),
((['git', '--no-pager', 'log', '--pretty=format:%s%n%n%b', ((['git', 'log', '--pretty=format:%s%n%n%b',
'fake_ancestor_sha...'],), 'fake_ancestor_sha...'],),
'foo'), 'foo'),
((['git', '--no-pager', 'config', 'user.email'],), 'me@example.com'), ((['git', 'config', 'user.email'],), 'me@example.com'),
stat_call, stat_call,
((['git', '--no-pager', 'config', 'gerrit.host'],), ''), ((['git', 'config', 'gerrit.host'],), ''),
((['git', '--no-pager', 'log', '--pretty=format:%s\n\n%b', ((['git', 'log', '--pretty=format:%s\n\n%b',
'fake_ancestor_sha..HEAD'],), 'fake_ancestor_sha..HEAD'],),
'desc\n'), 'desc\n'),
] ]
...@@ -182,7 +182,7 @@ class TestGitCl(TestCase): ...@@ -182,7 +182,7 @@ class TestGitCl(TestCase):
@classmethod @classmethod
def _git_upload_no_rev_calls(cls): def _git_upload_no_rev_calls(cls):
return [ return [
((['git', '--no-pager', 'config', 'core.editor'],), ''), ((['git', 'config', 'core.editor'],), ''),
] ]
@classmethod @classmethod
...@@ -191,27 +191,27 @@ class TestGitCl(TestCase): ...@@ -191,27 +191,27 @@ class TestGitCl(TestCase):
private_call = [] private_call = []
else: else:
private_call = [ private_call = [
((['git', '--no-pager', 'config', 'rietveld.private'],), '')] ((['git', 'config', 'rietveld.private'],), '')]
return [ return [
((['git', '--no-pager', 'config', 'core.editor'],), ''), ((['git', 'config', 'core.editor'],), ''),
((['git', '--no-pager', 'config', 'rietveld.cc'],), '') ((['git', 'config', 'rietveld.cc'],), '')
] + private_call + [ ] + private_call + [
((['git', '--no-pager', 'config', 'branch.master.base-url'],), ''), ((['git', 'config', 'branch.master.base-url'],), ''),
((['git', '--no-pager', ((['git',
'config', '--local', '--get-regexp', '^svn-remote\\.'],), 'config', '--local', '--get-regexp', '^svn-remote\\.'],),
(('', None), 0)), (('', None), 0)),
((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''), ((['git', 'rev-parse', '--show-cdup'],), ''),
((['git', '--no-pager', 'svn', 'info'],), ''), ((['git', 'svn', 'info'],), ''),
((['git', '--no-pager', ((['git',
'config', 'branch.master.rietveldissue', '1'],), ''), 'config', 'branch.master.rietveldissue', '1'],), ''),
((['git', '--no-pager', 'config', 'branch.master.rietveldserver', ((['git', 'config', 'branch.master.rietveldserver',
'https://codereview.example.com'],), ''), 'https://codereview.example.com'],), ''),
((['git', '--no-pager', ((['git',
'config', 'branch.master.rietveldpatchset', '2'],), ''), 'config', 'branch.master.rietveldpatchset', '2'],), ''),
((['git', '--no-pager', 'rev-parse', 'HEAD'],), 'hash'), ((['git', 'rev-parse', 'HEAD'],), 'hash'),
((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'hash'), ((['git', 'symbolic-ref', 'HEAD'],), 'hash'),
((['git', '--no-pager', ((['git',
'config', 'branch.hash.last-upload-hash', 'hash'],), ''), 'config', 'branch.hash.last-upload-hash', 'hash'],), ''),
] ]
...@@ -221,61 +221,61 @@ class TestGitCl(TestCase): ...@@ -221,61 +221,61 @@ 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', '--no-pager', ((['git',
'rev-parse', '--verify', diff_base],), fake_ancestor), 'rev-parse', '--verify', diff_base],), fake_ancestor),
((['git', '--no-pager', ((['git',
'merge-base', fake_ancestor, 'HEAD'],), fake_ancestor), 'merge-base', fake_ancestor, 'HEAD'],), fake_ancestor),
((['git', '--no-pager', ((['git',
'rev-list', '^' + fake_ancestor, 'HEAD'],), fake_cl), 'rev-list', '^' + fake_ancestor, 'HEAD'],), fake_cl),
# Mock a config miss (error code 1) # Mock a config miss (error code 1)
((['git', '--no-pager', ((['git',
'config', 'gitcl.remotebranch'],), (('', None), 1)), 'config', 'gitcl.remotebranch'],), (('', None), 1)),
# Call to GetRemoteBranch() # Call to GetRemoteBranch()
((['git', '--no-pager', ((['git',
'config', 'branch.%s.merge' % working_branch],), 'config', 'branch.%s.merge' % working_branch],),
'refs/heads/master'), 'refs/heads/master'),
((['git', '--no-pager', ((['git',
'config', 'branch.%s.remote' % working_branch],), 'origin'), 'config', 'branch.%s.remote' % working_branch],), 'origin'),
((['git', '--no-pager', 'rev-list', '^' + fake_ancestor, ((['git', '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', '--no-pager', ((['git',
'config', '--local', '--get-regexp', '^svn-remote\\.'],), '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', '--no-pager', ((['git',
'config', 'rietveld.server'],), 'codereview.example.com'), 'config', 'rietveld.server'],), 'codereview.example.com'),
((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'),
((['git', '--no-pager', 'config', '--int', '--get', ((['git', 'config', '--int', '--get',
'branch.working.git-cl-similarity'],), ''), 'branch.working.git-cl-similarity'],), ''),
((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'),
((['git', '--no-pager', 'config', '--int', '--get', ((['git', 'config', '--int', '--get',
'branch.working.git-find-copies'],), ''), 'branch.working.git-find-copies'],), ''),
((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'),
((['git', '--no-pager', ((['git',
'config', 'branch.working.merge'],), 'refs/heads/master'), 'config', 'branch.working.merge'],), 'refs/heads/master'),
((['git', '--no-pager', 'config', 'branch.working.remote'],), 'origin'), ((['git', 'config', 'branch.working.remote'],), 'origin'),
((['git', '--no-pager', 'rev-list', '--merges', ((['git', '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', '--no-pager', 'update-index', '--refresh', '-q'],), ''), ((['git', 'update-index', '--refresh', '-q'],), ''),
((['git', '--no-pager', 'diff-index', '--name-status', 'HEAD'],), ''), ((['git', 'diff-index', '--name-status', 'HEAD'],), ''),
((['git', '--no-pager', 'rev-list', '^refs/heads/working', ((['git', 'rev-list', '^refs/heads/working',
'refs/remotes/origin/master'],), 'refs/remotes/origin/master'],),
''), ''),
((['git', '--no-pager', ((['git',
'log', '--grep=^git-svn-id:', '-1', '--pretty=format:%H'],), 'log', '--grep=^git-svn-id:', '-1', '--pretty=format:%H'],),
'3fc18b62c4966193eb435baabe2d18a3810ec82e'), '3fc18b62c4966193eb435baabe2d18a3810ec82e'),
((['git', '--no-pager', ((['git',
'rev-list', '^3fc18b62c4966193eb435baabe2d18a3810ec82e', 'rev-list', '^3fc18b62c4966193eb435baabe2d18a3810ec82e',
'refs/remotes/origin/master'],), ''), 'refs/remotes/origin/master'],), ''),
((['git', '--no-pager', ((['git',
'merge-base', 'refs/remotes/origin/master', 'HEAD'],), 'merge-base', 'refs/remotes/origin/master', 'HEAD'],),
'fake_ancestor_sha'), 'fake_ancestor_sha'),
] ]
...@@ -283,29 +283,29 @@ class TestGitCl(TestCase): ...@@ -283,29 +283,29 @@ class TestGitCl(TestCase):
@classmethod @classmethod
def _dcommit_calls_normal(cls): def _dcommit_calls_normal(cls):
return [ return [
((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''), ((['git', 'rev-parse', '--show-cdup'],), ''),
((['git', '--no-pager', 'rev-parse', 'HEAD'],), ((['git', 'rev-parse', 'HEAD'],),
'00ff397798ea57439712ed7e04ab96e13969ef40'), '00ff397798ea57439712ed7e04ab96e13969ef40'),
((['git', '--no-pager', ((['git',
'diff', '--name-status', '--no-renames', '-r', 'fake_ancestor_sha...', 'diff', '--name-status', '--no-renames', '-r', 'fake_ancestor_sha...',
'.'],), '.'],),
'M\tPRESUBMIT.py'), 'M\tPRESUBMIT.py'),
((['git', '--no-pager', ((['git',
'config', 'branch.working.rietveldissue'],), '12345'), 'config', 'branch.working.rietveldissue'],), '12345'),
((['git', '--no-pager', ((['git',
'config', 'branch.working.rietveldpatchset'],), '31137'), 'config', 'branch.working.rietveldpatchset'],), '31137'),
((['git', '--no-pager', 'config', 'branch.working.rietveldserver'],), ((['git', 'config', 'branch.working.rietveldserver'],),
'codereview.example.com'), 'codereview.example.com'),
((['git', '--no-pager', 'config', 'user.email'],), 'author@example.com'), ((['git', 'config', 'user.email'],), 'author@example.com'),
((['git', '--no-pager', 'config', 'rietveld.tree-status-url'],), ''), ((['git', 'config', 'rietveld.tree-status-url'],), ''),
] ]
@classmethod @classmethod
def _dcommit_calls_bypassed(cls): def _dcommit_calls_bypassed(cls):
return [ return [
((['git', '--no-pager', ((['git',
'config', 'branch.working.rietveldissue'],), '12345'), 'config', 'branch.working.rietveldissue'],), '12345'),
((['git', '--no-pager', 'config', 'branch.working.rietveldserver'],), ((['git', '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 '
...@@ -315,31 +315,31 @@ class TestGitCl(TestCase): ...@@ -315,31 +315,31 @@ class TestGitCl(TestCase):
@classmethod @classmethod
def _dcommit_calls_3(cls): def _dcommit_calls_3(cls):
return [ return [
((['git', '--no-pager', ((['git',
'diff', '--no-ext-diff', '--stat', '--find-copies-harder', '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', '--no-pager', 'show-ref', '--quiet', '--verify', ((['git', 'show-ref', '--quiet', '--verify',
'refs/heads/git-cl-commit'],), 'refs/heads/git-cl-commit'],),
(('', None), 0)), (('', None), 0)),
((['git', '--no-pager', 'branch', '-D', 'git-cl-commit'],), ''), ((['git', 'branch', '-D', 'git-cl-commit'],), ''),
((['git', '--no-pager', 'show-ref', '--quiet', '--verify', ((['git', 'show-ref', '--quiet', '--verify',
'refs/heads/git-cl-cherry-pick'],), ''), 'refs/heads/git-cl-cherry-pick'],), ''),
((['git', '--no-pager', 'rev-parse', '--show-cdup'],), '\n'), ((['git', 'rev-parse', '--show-cdup'],), '\n'),
((['git', '--no-pager', 'checkout', '-q', '-b', 'git-cl-commit'],), ''), ((['git', 'checkout', '-q', '-b', 'git-cl-commit'],), ''),
((['git', '--no-pager', 'reset', '--soft', 'fake_ancestor_sha'],), ''), ((['git', 'reset', '--soft', 'fake_ancestor_sha'],), ''),
((['git', '--no-pager', 'commit', '-m', ((['git', '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', '--no-pager', ((['git',
'svn', 'dcommit', '-C50', '--no-rebase', '--rmdir'],), 'svn', 'dcommit', '-C50', '--no-rebase', '--rmdir'],),
(('', None), 0)), (('', None), 0)),
((['git', '--no-pager', 'checkout', '-q', 'working'],), ''), ((['git', 'checkout', '-q', 'working'],), ''),
((['git', '--no-pager', 'branch', '-D', 'git-cl-commit'],), ''), ((['git', 'branch', '-D', 'git-cl-commit'],), ''),
] ]
@staticmethod @staticmethod
...@@ -514,36 +514,36 @@ class TestGitCl(TestCase): ...@@ -514,36 +514,36 @@ class TestGitCl(TestCase):
@classmethod @classmethod
def _gerrit_base_calls(cls): def _gerrit_base_calls(cls):
return [ return [
((['git', '--no-pager', ((['git',
'config', 'rietveld.server'],), 'codereview.example.com'), 'config', 'rietveld.server'],), 'codereview.example.com'),
((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'master'), ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
((['git', '--no-pager', 'config', '--int', '--get', ((['git', 'config', '--int', '--get',
'branch.master.git-cl-similarity'],), ''), 'branch.master.git-cl-similarity'],), ''),
((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'master'), ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
((['git', '--no-pager', 'config', '--int', '--get', ((['git', 'config', '--int', '--get',
'branch.master.git-find-copies'],), ''), 'branch.master.git-find-copies'],), ''),
((['git', '--no-pager', 'update-index', '--refresh', '-q'],), ''), ((['git', 'update-index', '--refresh', '-q'],), ''),
((['git', '--no-pager', 'diff-index', '--name-status', 'HEAD'],), ''), ((['git', 'diff-index', '--name-status', 'HEAD'],), ''),
((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'master'), ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
((['git', '--no-pager', 'config', 'branch.master.merge'],), 'master'), ((['git', 'config', 'branch.master.merge'],), 'master'),
((['git', '--no-pager', 'config', 'branch.master.remote'],), 'origin'), ((['git', 'config', 'branch.master.remote'],), 'origin'),
((['git', '--no-pager', ((['git',
'merge-base', 'master', 'HEAD'],), 'fake_ancestor_sha'), 'merge-base', 'master', 'HEAD'],), 'fake_ancestor_sha'),
] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [
((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''), ((['git', 'rev-parse', '--show-cdup'],), ''),
((['git', '--no-pager', 'rev-parse', 'HEAD'],), '12345'), ((['git', 'rev-parse', 'HEAD'],), '12345'),
((['git', '--no-pager', ((['git',
'diff', '--name-status', '--no-renames', '-r', 'diff', '--name-status', '--no-renames', '-r',
'fake_ancestor_sha...', '.'],), 'fake_ancestor_sha...', '.'],),
'M\t.gitignore\n'), 'M\t.gitignore\n'),
((['git', '--no-pager', 'config', 'branch.master.rietveldissue'],), ''), ((['git', 'config', 'branch.master.rietveldissue'],), ''),
((['git', '--no-pager', ((['git',
'config', 'branch.master.rietveldpatchset'],), ''), 'config', 'branch.master.rietveldpatchset'],), ''),
((['git', '--no-pager', ((['git',
'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],), 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],),
'foo'), 'foo'),
((['git', '--no-pager', 'config', 'user.email'],), 'me@example.com'), ((['git', 'config', 'user.email'],), 'me@example.com'),
((['git', '--no-pager', ((['git',
'diff', '--no-ext-diff', '--stat', '--find-copies-harder', 'diff', '--no-ext-diff', '--stat', '--find-copies-harder',
'-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],), '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],),
'+dat'), '+dat'),
...@@ -552,25 +552,25 @@ class TestGitCl(TestCase): ...@@ -552,25 +552,25 @@ class TestGitCl(TestCase):
@staticmethod @staticmethod
def _gerrit_upload_calls(description, reviewers): def _gerrit_upload_calls(description, reviewers):
calls = [ calls = [
((['git', '--no-pager', 'config', 'gerrit.host'],), ((['git', 'config', 'gerrit.host'],),
'gerrit.example.com'), 'gerrit.example.com'),
((['git', '--no-pager', 'log', '--pretty=format:%s\n\n%b', ((['git', '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', '--no-pager', 'log', '--pretty=format:%s\n\n%b', ((['git', 'log', '--pretty=format:%s\n\n%b',
'fake_ancestor_sha..HEAD'],), 'fake_ancestor_sha..HEAD'],),
description), description),
((['git', '--no-pager', 'commit', '--amend', '-m', description],), ((['git', 'commit', '--amend', '-m', description],),
''), ''),
((['git', '--no-pager', 'log', '--pretty=format:%s\n\n%b', ((['git', 'log', '--pretty=format:%s\n\n%b',
'fake_ancestor_sha..HEAD'],), 'fake_ancestor_sha..HEAD'],),
description) description)
] ]
calls += [ calls += [
((['git', '--no-pager', 'config', 'rietveld.cc'],), '') ((['git', '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
...@@ -580,7 +580,7 @@ class TestGitCl(TestCase): ...@@ -580,7 +580,7 @@ class TestGitCl(TestCase):
'--reviewer=' + email for email in sorted(reviewers)) '--reviewer=' + email for email in sorted(reviewers))
receive_pack += '' receive_pack += ''
calls += [ calls += [
((['git', '--no-pager', ((['git',
'push', receive_pack, 'origin', 'HEAD:refs/for/master'],), 'push', receive_pack, 'origin', 'HEAD:refs/for/master'],),
'') '')
] ]
...@@ -649,40 +649,40 @@ class TestGitCl(TestCase): ...@@ -649,40 +649,40 @@ 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', '--no-pager', 'config', 'rietveld.server', ((['git', 'config', 'rietveld.server',
'gerrit.chromium.org'],), ''), 'gerrit.chromium.org'],), ''),
((['git', '--no-pager', 'config', '--unset-all', 'rietveld.cc'],), ''), ((['git', 'config', '--unset-all', 'rietveld.cc'],), ''),
((['git', '--no-pager', 'config', '--unset-all', ((['git', 'config', '--unset-all',
'rietveld.private'],), ''), 'rietveld.private'],), ''),
((['git', '--no-pager', 'config', '--unset-all', ((['git', 'config', '--unset-all',
'rietveld.tree-status-url'],), ''), 'rietveld.tree-status-url'],), ''),
((['git', '--no-pager', 'config', '--unset-all', ((['git', 'config', '--unset-all',
'rietveld.viewvc-url'],), ''), 'rietveld.viewvc-url'],), ''),
((['git', '--no-pager', 'config', 'gerrit.host', ((['git', 'config', 'gerrit.host',
'gerrit.chromium.org'],), ''), 'gerrit.chromium.org'],), ''),
((['git', '--no-pager', 'config', 'gerrit.port', '29418'],), ''), ((['git', 'config', 'gerrit.port', '29418'],), ''),
# DownloadHooks(False) # DownloadHooks(False)
((['git', '--no-pager', 'config', 'gerrit.host'],), ((['git', 'config', 'gerrit.host'],),
'gerrit.chromium.org'), 'gerrit.chromium.org'),
((['git', '--no-pager', 'config', 'rietveld.server'],), ((['git', 'config', 'rietveld.server'],),
'gerrit.chromium.org'), 'gerrit.chromium.org'),
((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''), ((['git', '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', '--no-pager', 'config', 'rietveld.server'],), ((['git', 'config', 'rietveld.server'],),
'gerrit.chromium.org'), 'gerrit.chromium.org'),
(('Rietveld server (host[:port]) [https://gerrit.chromium.org]:',), (('Rietveld server (host[:port]) [https://gerrit.chromium.org]:',),
''), ''),
((['git', '--no-pager', 'config', 'rietveld.cc'],), ''), ((['git', 'config', 'rietveld.cc'],), ''),
(('CC list:',), ''), (('CC list:',), ''),
((['git', '--no-pager', 'config', 'rietveld.private'],), ''), ((['git', 'config', 'rietveld.private'],), ''),
(('Private flag (rietveld only):',), ''), (('Private flag (rietveld only):',), ''),
((['git', '--no-pager', 'config', 'rietveld.tree-status-url'],), ''), ((['git', 'config', 'rietveld.tree-status-url'],), ''),
(('Tree status URL:',), ''), (('Tree status URL:',), ''),
((['git', '--no-pager', 'config', 'rietveld.viewvc-url'],), ''), ((['git', '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),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment