aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2023-06-09 12:36:56 -0400
committerMike Frysinger <vapier@google.com>2023-06-22 16:06:09 +0000
commit735b207c223c85523683ba099c9e56934c3ec492 (patch)
tree4a95d58a0de50bffe0cf717a501b997410b26e9c
parente7cbdee8173cea8445374476e410f8935c3a957c (diff)
downloadrepohooks-735b207c223c85523683ba099c9e56934c3ec492.tar.gz
hooks: gofmt: fix argument handling
Since gofmt iterates over the filtered set of files by hand, and reads it from the git commit to run through the formatter, we don't want to expand the list of files into the base command. If they end up there, gofmt will run on them as they exist on disk, not on the content as they exist in the git commit. Also make sure to pass the set of custom gofmt arguments to the fixup command so it gets run correctly. Bug: 116112526 Test: unittests Change-Id: I3615afa97817482c4e0482053fa308bed8c8d12b
-rw-r--r--rh/hooks.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/rh/hooks.py b/rh/hooks.py
index c90c0a3..84d0f4d 100644
--- a/rh/hooks.py
+++ b/rh/hooks.py
@@ -858,13 +858,14 @@ def check_gofmt(project, commit, _desc, diff, options=None):
return None
gofmt = options.tool_path('gofmt')
- cmd = [gofmt, '-l'] + options.args((), filtered)
+ cmd = [gofmt, '-l'] + options.args()
+ fixup_cmd = [gofmt, '-w'] + options.args()
+
ret = []
for d in filtered:
data = rh.git.get_file_content(commit, d.file)
result = _run(cmd, input=data)
if result.stdout:
- fixup_cmd = [gofmt, '-w']
ret.append(rh.results.HookResult(
'gofmt', project, commit, error=result.stdout,
files=(d.file,), fixup_cmd=fixup_cmd))