From d6ddc1cb9a814dce5604fcfc3cd557579d8e6fb6 Mon Sep 17 00:00:00 2001 From: "digit@chromium.org" Date: Fri, 25 Oct 2013 15:36:32 +0000 Subject: [PATCH] Fix "git cl format" when newer clang-format version is installed. Newer versions of clang-format-diff.py now require a -i flag to explicitely apply edits, otherwise they just print a diff, which make "git cl format" a no-op. This patch fixes the issue by probing the script's help text to see if the flag is needed. If it is, it is added automatically. BUG=NONE R=maruel@chromium.org Review URL: https://codereview.chromium.org/44263004 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@231020 0039d316-1c4b-4281-b951-d872f2087c98 --- git_cl.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/git_cl.py b/git_cl.py index cb93095c8d..ebe285bb1f 100755 --- a/git_cl.py +++ b/git_cl.py @@ -2267,6 +2267,14 @@ def CMDformat(parser, args): if not os.path.exists(cfd_path): DieWithError('Could not find clang-format-diff at %s.' % cfd_path) cmd = [sys.executable, cfd_path, '-p0', '-style', 'Chromium'] + + # Newer versions of clang-format-diff.py require an explicit -i flag + # to apply the edits to files, otherwise it just displays a diff. + # Probe the usage string to verify if this is needed. + help_text = RunCommand([sys.executable, cfd_path, '-h']) + if '[-i]' in help_text: + cmd.append('-i') + RunCommand(cmd, stdin=diff_output, cwd=top_dir) return 0