diff options
author | Mike Frysinger <vapier@google.com> | 2022-12-19 20:25:31 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2022-12-19 20:25:31 +0000 |
commit | 3df242c4fe64f9b3f5e4cad9c861f6c33caa12b1 (patch) | |
tree | c01f39edc5287991004c1098926fe51680a2c340 | |
parent | 3f7deee5b180403bc01dc66d57c64eb570643213 (diff) | |
download | repohooks-3df242c4fe64f9b3f5e4cad9c861f6c33caa12b1.tar.gz |
Revert "Propagate google-java-format-diff.py's failures"
This reverts commit 3f7deee5b180403bc01dc66d57c64eb570643213.
Reason for revert: doesn't appear to actually work, doesn't follow
styleguide, doesn't pass linting, etc...
Bug: 254300364
Change-Id: I50c3ddfb7d6e99539eba610b427ad2d0a039c70a
-rwxr-xr-x | tools/google-java-format.py | 45 |
1 files changed, 8 insertions, 37 deletions
diff --git a/tools/google-java-format.py b/tools/google-java-format.py index e25d781..8a4f739 100755 --- a/tools/google-java-format.py +++ b/tools/google-java-format.py @@ -28,8 +28,8 @@ del _path # We have to import our local modules after the sys.path tweak. We can't use # relative imports because this is an executable program, not a module. # pylint: disable=wrong-import-position -import rh.shell # pylint: disable=import-error -import rh.utils # pylint: disable=import-error +import rh.shell +import rh.utils def get_parser(): @@ -52,8 +52,6 @@ def get_parser(): parser.add_argument('files', nargs='*', help='If specified, only consider differences in ' 'these files.') - parser.add_argument('--verbose', action='store_true', - help='Explain what is being done.') return parser @@ -76,45 +74,18 @@ def main(argv): diff_cmd.extend(['--'] + opts.files) diff = rh.utils.run(diff_cmd, capture_output=True).stdout - format_cmd = [ - opts.google_java_format_diff, - '-p1', - '--aosp', - '-b', - format_path, - ] + cmd = [opts.google_java_format_diff, '-p1', '--aosp', '-b', format_path] if opts.fix: - format_cmd.extend(['-i']) + cmd.extend(['-i']) if not opts.sort_imports: - format_cmd.extend(['--skip-sorting-imports']) + cmd.extend(['--skip-sorting-imports']) - format_cmd_result = rh.utils.run( - format_cmd, input=diff, capture_output=True) - - if format_cmd_result.returncode != 0: - print("Failed due to non-zero exit code.") - if opts.verbose: - # print out the full command that was called, including pipes - print("Called:") - print(f" {' '.join(diff_cmd)} |") - print(f" {' '.join(format_cmd)}") - for line in format_cmd_result.stdout.splitlines(): - print(f"[captured stdout] {line}") - for line in format_cmd_result.stderr.splitlines(): - print(f"[captured stderr] {line}") - return format_cmd_result.returncode - if format_cmd_result.stdout: + stdout = rh.utils.run(cmd, input=diff, capture_output=True).stdout + if stdout: print('One or more files in your commit have Java formatting errors.') print(f'You can run: {sys.argv[0]} --fix {rh.shell.cmd_to_str(argv)}') return 1 - if format_cmd_result.stderr: - # We need to use stderr to catch errors in google-java-format since we - # cannot listen for a non-zero error code until - # https://github.com/google/google-java-format/pull/848 is merged. - print("Errors have been captured in stderr.") - for line in format_cmd_result.stderr.splitlines(): - print(f"[captured stderr] {line}") - return 1 + return 0 |