git » chasquid » commit 7e38a87

hooks: Fix dkimpy's diff check

author Alberto Bertogli
2022-08-27 22:58:26 UTC
committer Alberto Bertogli
2022-08-27 22:58:26 UTC
parent e85c31782b88b38f5713a823971dc9c191183edd

hooks: Fix dkimpy's diff check

When running a diff for dkimpy's output, we expect that diff to exit with
non-zero code.

Unfortunately, the way we set that expectation (by prefixing the diff
invocation with `!` is incorrect.

Running `! diff ...` will not cause the hook to fail if diff exits with
0, instead `!` will cause the exit code to be ignored.

This patch fixes the problem by running `diff ... && exit 1` instead.

This was caught by shellcheck, https://www.shellcheck.net/wiki/SC2251.

etc/chasquid/hooks/post-data +2 -2
test/t-19-dkimpy/config/hooks/post-data +2 -2

diff --git a/etc/chasquid/hooks/post-data b/etc/chasquid/hooks/post-data
index cbf3c8e..e9fe9ca 100755
--- a/etc/chasquid/hooks/post-data
+++ b/etc/chasquid/hooks/post-data
@@ -107,9 +107,9 @@ if [ "$AUTH_AS" != "" ] && command -v dkimsign >/dev/null; then
 			# dkimpy doesn't provide a way to just show the new
 			# headers, so we have to compute the difference.
 			# ALSOCHANGE(test/t-19-dkimpy/config/hooks/post-data)
-			! diff --changed-group-format='%>' \
+			diff --changed-group-format='%>' \
 				--unchanged-group-format='' \
-				"$TF" "$TF.dkimout"
+				"$TF" "$TF.dkimout" && exit 1
 			rm "$TF.dkimout"
 		else
 			# driusan/dkim
diff --git a/test/t-19-dkimpy/config/hooks/post-data b/test/t-19-dkimpy/config/hooks/post-data
index 7a129c1..2fb9f99 100755
--- a/test/t-19-dkimpy/config/hooks/post-data
+++ b/test/t-19-dkimpy/config/hooks/post-data
@@ -31,9 +31,9 @@ if [ "$AUTH_AS" != "" ]; then
 	# dkimpy doesn't provide a way to just show the new headers, so we
 	# have to compute the difference.
 	# ALSOCHANGE(etc/chasquid/hooks/post-data)
-	! diff --changed-group-format='%>' \
+	diff --changed-group-format='%>' \
 		--unchanged-group-format='' \
-		"$TF" "$TF.dkimout"
+		"$TF" "$TF.dkimout" && exit 1
 	rm "$TF.dkimout"
 else
 	# NOTE: This is using driusan/dkim instead of dkimpy, because dkimpy can't be