Allow users to specify list of files/path to google-java-format
Bug: 69068870
Test: Ran "repo upload" and verified that google-java-format runs on all
modified files when a list of files/path is not specified.
Test: Ran "repo upload" and verified that google-java-format runs on all
modified files from a list of files/path.
Change-Id: Ib07c9fa81ffbcf7ef38feaf6ea40b321c701f998
diff --git a/tools/google-java-format.py b/tools/google-java-format.py
index b0b164c..0022c9d 100755
--- a/tools/google-java-format.py
+++ b/tools/google-java-format.py
@@ -52,6 +52,9 @@
# default to not sort imports, while letting callers override as desired.
parser.add_argument('--sort-imports', action='store_true',
help='If true, imports will be sorted.')
+ parser.add_argument('files', nargs='*',
+ help='If specified, only consider differences in '
+ 'these files.')
return parser
@@ -79,6 +82,7 @@
# TODO: Delegate to the tool once this issue is resolved:
# https://github.com/google/google-java-format/issues/107
diff_cmd = ['git', 'diff', '--no-ext-diff', '-U0', '%s^!' % opts.commit]
+ diff_cmd.extend(['--'] + opts.files)
diff = rh.utils.run_command(diff_cmd, capture_output=True).output
cmd = [opts.google_java_format_diff, '-p1', '--aosp']