Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Unified Diff: git_cl.py

Issue 180533012: Add git cl format --diff option to print format diff without modifying files (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: git_cl.py
diff --git a/git_cl.py b/git_cl.py
index e8c769f49405c8bad1f497aa262aa8973fa24fad..82359c09130f310742211dff33decdb4faddfdfc 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698