aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2023-06-09 11:22:23 -0400
committerMike Frysinger <vapier@google.com>2023-06-23 23:31:38 -0400
commite2217142cf18e5a894c94eefe120a22bb8b852db (patch)
tree08f6453d8b1ac4d39f7e72725e90b5f089ee4dee
parentc400921fda11c5c802b7d4890474e9ec5a7e579b (diff)
downloadrepohooks-e2217142cf18e5a894c94eefe120a22bb8b852db.tar.gz
hooks: bpfmt: display formatting diff on errors
`bpfmt -l` just shows "<standard input>" when there's a formatting error which isn't super useful to users. Switch to `bpfmt -d` to get an actual diff of broken formatting. Also hoist the definition of fixup_cmd outside the loop since it doesn't change between runs anymore -- the set of files is passed via the results object now. Bug: 132785638 Test: unittests Change-Id: I9d564ac4b7fd3801b73b5c6869a2529f337cc3f0
-rw-r--r--rh/hooks.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/rh/hooks.py b/rh/hooks.py
index 457a440..d260e1b 100644
--- a/rh/hooks.py
+++ b/rh/hooks.py
@@ -346,15 +346,17 @@ def check_bpfmt(project, commit, _desc, diff, options=None):
bpfmt = options.tool_path('bpfmt')
bpfmt_options = options.args((), filtered)
- cmd = [bpfmt, '-l'] + bpfmt_options
+ cmd = [bpfmt, '-d'] + bpfmt_options
+ fixup_cmd = [bpfmt, '-w']
+ if '-s' in bpfmt_options:
+ fixup_cmd.append('-s')
+ fixup_cmd.append('--')
+
ret = []
for d in filtered:
data = rh.git.get_file_content(commit, d.file)
result = _run(cmd, input=data)
if result.stdout:
- fixup_cmd = [bpfmt, '-w']
- if '-s' in bpfmt_options:
- fixup_cmd.append('-s')
ret.append(rh.results.HookResult(
'bpfmt', project, commit,
error=result.stdout,