From 04d5a22ea966c9fc3c803a1424738759d839f99e Mon Sep 17 00:00:00 2001 From: "wittman@chromium.org" Date: Fri, 7 Mar 2014 18:30:42 +0000 Subject: [PATCH] Add git cl format --diff option to print format diff without modifying files BUG=none Review URL: https://codereview.chromium.org/180533012 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@255667 0039d316-1c4b-4281-b951-d872f2087c98 --- git_cl.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/git_cl.py b/git_cl.py index e8c769f49..82359c091 100755 --- a/git_cl.py +++ b/git_cl.py @@ -2335,6 +2335,8 @@ def CMDformat(parser, args): help='Reformat the full content of all touched files') parser.add_option('--dry-run', action='store_true', help='Don\'t modify any file on disk.') + parser.add_option('--diff', action='store_true', + help='Print diff to stdout rather than modifying files.') opts, args = parser.parse_args(args) # git diff generates paths against the root of the repository. Change @@ -2399,9 +2401,11 @@ def CMDformat(parser, args): print "Nothing to format." return 0 cmd = [clang_format_tool] - if not opts.dry_run: + if not opts.dry_run and not opts.diff: cmd.append('-i') stdout = RunCommand(cmd + files, cwd=top_dir) + if opts.diff: + sys.stdout.write(stdout) else: env = os.environ.copy() env['PATH'] = os.path.dirname(clang_format_tool) @@ -2413,10 +2417,12 @@ def CMDformat(parser, args): DieWithError(e) cmd = [sys.executable, script, '-p0'] - if not opts.dry_run: + if not opts.dry_run and not opts.diff: cmd.append('-i') stdout = RunCommand(cmd, stdin=diff_output, cwd=top_dir, env=env) + if opts.diff: + sys.stdout.write(stdout) if opts.dry_run and len(stdout) > 0: return 2