Skip to content

Contribution tips and tricks

Matthew edited this page Jul 8, 2024 · 14 revisions

Automatically signing every commit

The Contribution Guide explains the role the Developer Certificate of Origin plays in contributions to the CUE project. It also explains how git commit -s can be used to sign-off each commit. But:

  • it's easy to forget the -s flag;
  • it's not always possible/easy to fix up other tools that wrap the git commit step.

You can automate the sign-off step using a git hook. Run the following commands in the root of a git repository where you want to automatically sign-off each commit:

cat <<'EOD' > .git/hooks/prepare-commit-msg
#!/bin/sh

NAME=$(git config user.name)
EMAIL=$(git config user.email)

if [ -z "$NAME" ]; then
    echo "empty git config user.name"
    exit 1
fi

if [ -z "$EMAIL" ]; then
    echo "empty git config user.email"
    exit 1
fi

git interpret-trailers --if-exists doNothing --trailer \
    "Signed-off-by: $NAME <$EMAIL>" \
    --in-place "$1"
EOD
chmod +x .git/hooks/prepare-commit-msg

(if you already have a prepare-commit-msg hook, adapt it accordingly).