Commit 6c18a1af authored by Aiden Benner's avatar Aiden Benner Committed by Commit Bot

Fix git cl format --python when diff.noprefix flag is set

Adding the diff.noprefix flag to .gitconfig broke python
formatting because git diffs were being parsed with regex
that relied on the default git diff prefixs.

This CL fix's this issue by always specifying prefix flags
for git diffs when formatting python.

Bug:846432
Change-Id: Ifde305da9574e6b46455a0237703b7364fac77e4
Reviewed-on: https://chromium-review.googlesource.com/c/1349809Reviewed-by: 's avatarMarc-Antoine Ruel <maruel@chromium.org>
Commit-Queue: Marc-Antoine Ruel <maruel@chromium.org>
parent 25c4fce2
......@@ -683,7 +683,7 @@ def _ComputeDiffLineRanges(files, upstream_commit):
if len(files) == 0:
return {}
# Take diff and find the line ranges where there are changes.
# Take the git diff and find the line ranges where there are changes.
diff_cmd = BuildGitDiffCmd('-U0', upstream_commit, files, allow_prefix=True)
diff_output = RunGit(diff_cmd)
......@@ -5322,7 +5322,11 @@ def BuildGitDiffCmd(diff_type, upstream_commit, args, allow_prefix=False):
# Generate diff for the current branch's changes.
diff_cmd = ['-c', 'core.quotePath=false', 'diff', '--no-ext-diff']
if not allow_prefix:
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.
diff_cmd += ['--src-prefix=a/', '--dst-prefix=b/']
else:
diff_cmd += ['--no-prefix']
diff_cmd += [diff_type, upstream_commit, '--']
......
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