Commit f548d08a authored by Mark Mentovai's avatar Mark Mentovai Committed by Commit Bot

Make git blame test pass independently of core.abbrev setting

7-digit hashes are bogus, so I run with core.abbrev = 12.

Non-default settings for core.abbrev caused the git blame test to fail,
because it was hard-coded to look for exactly 7 digits. This change
allows an --abbrev option to be passed to the git-blame wrapper, and
ensures that the same value is used for the git-blame operation and the
computed expectation.

TEST=tests/git_common_test.py GitReadOnlyFunctionsTest.testBlame

Change-Id: I83cbf4dd7267ea36607119bef52f303d59c3f840
Reviewed-on: https://chromium-review.googlesource.com/451124Reviewed-by: 's avatarAndrii Shyshkalov <tandrii@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
parent 600d309d
......@@ -294,12 +294,14 @@ def die(message, *args):
sys.exit(1)
def blame(filename, revision=None, porcelain=False, *_args):
def blame(filename, revision=None, porcelain=False, abbrev=None, *_args):
command = ['blame']
if porcelain:
command.append('-p')
if revision is not None:
command.append(revision)
if abbrev is not None:
command.append('--abbrev=%d' % abbrev)
command.extend(['--', filename])
return run(*command)
......
......@@ -286,15 +286,16 @@ class GitReadOnlyFunctionsTest(git_test_utils.GitRepoReadOnlyTestBase,
return info.split('\n')
# Expect to blame line 1 on C, line 2 on E.
c_short = self.repo['C'][:8]
ABBREV_LEN = 7
c_short = self.repo['C'][:1 + ABBREV_LEN]
c_author = self.repo.show_commit('C', format_string='%an %ai')
e_short = self.repo['E'][:8]
e_short = self.repo['E'][:1 + ABBREV_LEN]
e_author = self.repo.show_commit('E', format_string='%an %ai')
expected_output = ['%s (%s 1) file2 - vanilla' % (c_short, c_author),
'%s (%s 2) file2 - merged' % (e_short, e_author)]
self.assertEqual(expected_output,
self.repo.run(self.gc.blame, 'some/files/file2',
'tag_D').split('\n'))
'tag_D', abbrev=ABBREV_LEN).split('\n'))
# Test porcelain.
expected_output = []
......
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