From fe6a359a803f55829ede3666215d080f6775f173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=9Aniatowski?= Date: Tue, 12 Mar 2024 07:02:53 +0000 Subject: [PATCH] Fix git cl format --diff --dry-run for Java files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Commit-Queue: Tomasz Ĺšniatowski --- git_cl.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/git_cl.py b/git_cl.py index 52bc105c7..0ea39e8c3 100755 --- a/git_cl.py +++ b/git_cl.py @@ -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: