diff --git a/presubmit_support.py b/presubmit_support.py index c6242495fc..3e549a281a 100755 --- a/presubmit_support.py +++ b/presubmit_support.py @@ -1059,7 +1059,8 @@ class _GitDiffCache(_DiffCache): files=[], full_move=True, branch=self._upstream, - branch_head=self._end_commit) + branch_head=self._end_commit, + allow_prefix=True) # Compute a single diff for all files and parse the output; with git # this is much faster than computing one diff for each file. self._diffs_by_file = _parse_unified_diff(unified_diff) diff --git a/scm.py b/scm.py index 1793b400f3..1df082af97 100644 --- a/scm.py +++ b/scm.py @@ -1020,7 +1020,8 @@ class GIT(object): branch: Optional[str] = None, branch_head: str = 'HEAD', full_move: bool = False, - files: Optional[Iterable[str]] = None) -> str: + files: Optional[Iterable[str]] = None, + allow_prefix: bool = False) -> str: """Diffs against the upstream branch or optionally another branch. full_move means that move or copy operations should completely recreate the @@ -1034,10 +1035,18 @@ class GIT(object): 'diff', '-p', '--no-color', - '--no-prefix', '--no-ext-diff', - branch + "..." + branch_head, ] + + if allow_prefix: + # explicitly setting --src-prefix and --dst-prefix is necessary in the + # case that diff.noprefix is set in the user's git config. + command.extend(['--src-prefix=a/', '--dst-prefix=b/']) + else: + command.extend(['--no-prefix']) + + command.append(branch + "..." + branch_head) + if full_move: command.append('--no-renames') else: diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py index 3c6584f658..c863b9edd4 100755 --- a/tests/presubmit_unittest.py +++ b/tests/presubmit_unittest.py @@ -419,7 +419,8 @@ class PresubmitUnittest(PresubmitTestsBase): files=[], full_move=True, branch='upstream', - branch_head='end_commit') + branch_head='end_commit', + allow_prefix=True) f_blat = os.path.normpath('boo/blat.cc')