Commit 04d5a22e authored by wittman@chromium.org's avatar wittman@chromium.org

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
parent 6352945d
......@@ -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
......
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