From f548d08a5dfc8bb22cfec445bcca0405f6a489e5 Mon Sep 17 00:00:00 2001 From: Mark Mentovai Date: Wed, 8 Mar 2017 13:32:00 -0500 Subject: [PATCH] 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/451124 Reviewed-by: Andrii Shyshkalov Commit-Queue: Mark Mentovai --- git_common.py | 4 +++- tests/git_common_test.py | 7 ++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/git_common.py b/git_common.py index b1e4af824..ab936cb17 100644 --- a/git_common.py +++ b/git_common.py @@ -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) diff --git a/tests/git_common_test.py b/tests/git_common_test.py index d107f3c7d..210ff2346 100755 --- a/tests/git_common_test.py +++ b/tests/git_common_test.py @@ -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 = []