Skip to content

templates: pre-push hook: check for missing GPG signatures

Sebastian Götte git 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v2 Latest1 patch 2 repliesIn review

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/1templates: pre-push hook: check for missing GPG signatures (was: Re: [PATCH] Add .gitconfig variable commit.gpg-sign)templates/hooks--pre-push.sample+10 -121 reply
1/1templates: pre-push hook: check for missing GPG signaturestemplates/hooks--pre-push.sample+15 -80 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/1] templates: pre-push hook: check for missing GPG signatures
Quoted 1 line · Junio C Hamano

None of the above is part of a proper commit log message, is it?

Fixed (I hope)

Quoted 5 lines

templates/hooks--pre-push.sample

Quoted 4 lines
templates/hooks--pre-push.sample +0 -0
old mode 100644
new mode 100755

Why?

According to man githooks(5):

Quoted 2 lines

It is also a requirement for a given hook to be executable. However - in a freshly initialized repository - the .sample files are executable by default.

This file is the only one in templates/ that was not executable, so I assume this was a mistake.

Quoted 10 lines

templates/hooks--pre-push.sample

Quoted 6 lines

index 15ab6d8..08a72df

templates/hooks--pre-push.sample +1 -2
-# This sample shows how to prevent push of commits where the log message starts
-# with "WIP" (work in progress).
+# This sample shows how to prevent pushing commits without good GPG signatures

What justifies to remove existing demonstration? It is far easier for the end users to remove parts that do not apply to their needs, than coming up with a solution to add themselves without help from an example.

re-added it.

Quoted 3 lines
Quoted 1 line

+ec=0

I think it is more customary to call this kind of variable "ret" or "retval", not an abbreviation for "european commission" ;-).

renamed it to "exitcode".

Quoted 2 lines
Quoted 1 line

-IFS=' '

Why?

Otherwise in the for-loop below the output of the pipe chain is not correctly split by newlines. Also AFAIK, this is not needed: I think the default '<space><tab><newline>' is just fine here.

Quoted 2 lines

templates/hooks--pre-push.sample

Quoted 1 line
templates/hooks--pre-push.sample +1 -0
+		commits=`git log --format="%G? %h" "$range" | grep -v '^G' | cut -d\  -f2`

Useless use of cut. You could do

I just tried this, but I really want the script to output a list of *all* offending commits (instead of exiting on the first problem). For this I need the exitcode variable, but since at least bash executes the while loop in a subshell due to the preceding pipe, I have some issues getting that out of the subshell. This is what the code looked like without grep/cut:

Quoted 5 lines

# Check for missing good GPG signatures
git log --format="%G? %h" "$range" |
(
exitcode=0
while read sign commit

Quoted 8 lines

do
test "$sign" = G && continue
echo "Commit $commit does not have a good GPG signature" exitcode=1
done
exit $exitcode
)
let exitcode=exitcode\|$?

This is less readable and only spawns one process less.

Sebastian Götte (1):
templates: pre-push hook: check for missing GPG signatures

 templates/hooks--pre-push.sample | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
 mode change 100644 => 100755 templates/hooks--pre-push.sample
Signature · 1 line
1.8.2