From 6c18a1afa1a7a30421775c8d6c1cfb7edb3f272a Mon Sep 17 00:00:00 2001 From: Aiden Benner Date: Fri, 23 Nov 2018 20:18:23 +0000 Subject: [PATCH] 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/1349809 Reviewed-by: Marc-Antoine Ruel Commit-Queue: Marc-Antoine Ruel --- git_cl.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/git_cl.py b/git_cl.py index 06a7c1ef0..043717ba6 100755 --- a/git_cl.py +++ b/git_cl.py @@ -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, '--']