Ver código fonte

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 <tandrii@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
Mark Mentovai 8 anos atrás
pai
commit
f548d08a5d
2 arquivos alterados com 7 adições e 4 exclusões
  1. 3 1
      git_common.py
  2. 4 3
      tests/git_common_test.py

+ 3 - 1
git_common.py

@@ -294,12 +294,14 @@ def die(message, *args):
   sys.exit(1)
   sys.exit(1)
 
 
 
 
-def blame(filename, revision=None, porcelain=False, *_args):
+def blame(filename, revision=None, porcelain=False, abbrev=None, *_args):
   command = ['blame']
   command = ['blame']
   if porcelain:
   if porcelain:
     command.append('-p')
     command.append('-p')
   if revision is not None:
   if revision is not None:
     command.append(revision)
     command.append(revision)
+  if abbrev is not None:
+    command.append('--abbrev=%d' % abbrev)
   command.extend(['--', filename])
   command.extend(['--', filename])
   return run(*command)
   return run(*command)
 
 

+ 4 - 3
tests/git_common_test.py

@@ -286,15 +286,16 @@ class GitReadOnlyFunctionsTest(git_test_utils.GitRepoReadOnlyTestBase,
       return info.split('\n')
       return info.split('\n')
 
 
     # Expect to blame line 1 on C, line 2 on E.
     # 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')
     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')
     e_author = self.repo.show_commit('E', format_string='%an %ai')
     expected_output = ['%s (%s 1) file2 - vanilla' % (c_short, c_author),
     expected_output = ['%s (%s 1) file2 - vanilla' % (c_short, c_author),
                        '%s (%s 2) file2 - merged' % (e_short, e_author)]
                        '%s (%s 2) file2 - merged' % (e_short, e_author)]
     self.assertEqual(expected_output,
     self.assertEqual(expected_output,
                      self.repo.run(self.gc.blame, 'some/files/file2',
                      self.repo.run(self.gc.blame, 'some/files/file2',
-                                   'tag_D').split('\n'))
+                                   'tag_D', abbrev=ABBREV_LEN).split('\n'))
 
 
     # Test porcelain.
     # Test porcelain.
     expected_output = []
     expected_output = []