Fix git cl format --diff --dry-run for Java files

A recent change added --diff support for Java files in git cl format,
but unfortunately it broke the behavior when both --dry-run and --diff
are passed, and made git cl format indicate that all changed files need
to be reformatted.

Fix so that --diff overrides --dry-run when running google-java-format,
as passing --dry-run makes the formatter only output file names which
then confused the diff creation code. This makes behavior for Java in
line with C++ where --dry-run doesn't change much if --diff is used.

Change-Id: I7f8eecb13064a0046935489e6c5cf3af566f7f56
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5357818
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Tomasz Śniatowski <tomasz.sniatowski@xperi.com>
changes/18/5357818/2
Tomasz Śniatowski 1 year ago committed by LUCI CQ
parent 6ec5a9ab60
commit fe6a359a80

@ -6128,10 +6128,11 @@ def _RunGoogleJavaFormat(opts, paths, top_dir, upstream_commit):
return 0
base_cmd = [google_java_format, '--aosp']
if opts.dry_run:
base_cmd += ['--dry-run']
elif not opts.diff:
base_cmd += ['--replace']
if not opts.diff:
if opts.dry_run:
base_cmd += ['--dry-run']
else:
base_cmd += ['--replace']
changed_lines_only = not (opts.full or settings.GetFormatFullByDefault())
if changed_lines_only:

Loading…
Cancel
Save