All commits should include a sign-off statement with the following format:
Signed-off-by: CONTRIBUTOR NAME <EMAIL ADDRESS>
These can be added manually to each commit by including the -s flag:
git commit -s -m "fabulous coding by chatgpt"
If commits to a PR are made without a sign-off statement, they will fail checks. It is possible to rebase these commits as long as you are the only one that has authored commits to a PR. In order to avoid issues when that is not the case, we should implement some automation so that sign off statements can be added to all commits and so that commits cannot be made if they lack a sign-off statement.
Proposed approach
One option for doing this is to add a commit-msg hook like the following:
goes in .git/hooks/commit-msg for each repo then made executable: chmod +x commit-msg
#!/bin/sh
NAME=$(git config user.name)
EMAIL=$(git config user.email)
AUTO_SIGN=$(git config user.auto-signoff)
SELF_SIGN=$(grep -qi "^Signed-off-by: $NAME <$EMAIL>" "$1")
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
# auto sign-off if configured
if [ "$AUTO_SIGN" ]; then
git interpret-trailers --if-exists doNothing --trailer \
"Signed-off-by: $NAME <$EMAIL>" \
--in-place "$1"
fi
# error if auto sign-off not configured and no manual sign-off
if [ ! "$SELF_SIGN" ] &&[ ! "$AUTO_SIGN" ]; then
echo "ERROR:\n a sign-off statement is required\n either commit with -s flag or run git config user.auto-signoff true"
exit 1
fi
The dev just needs to then run git config user.auto-signoff true and will get an error and helpful message if they have not set this config or included the -s flag.
Background
All commits should include a sign-off statement with the following format:
These can be added manually to each commit by including the
-s
flag:If commits to a PR are made without a sign-off statement, they will fail checks. It is possible to rebase these commits as long as you are the only one that has authored commits to a PR. In order to avoid issues when that is not the case, we should implement some automation so that sign off statements can be added to all commits and so that commits cannot be made if they lack a sign-off statement.
Proposed approach
One option for doing this is to add a
commit-msg
hook like the following:goes in .git/hooks/commit-msg for each repo then made executable:
chmod +x commit-msg
The dev just needs to then run
git config user.auto-signoff true
and will get an error and helpful message if they have not set this config or included the-s
flag.