Skip to content

Commit c9f099c

Browse files
committed
Add commit-msg hook example for DCO checking
Signed-off-by: Pierre R. Mai <[email protected]>
1 parent 0ef06cd commit c9f099c

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

doc/howtocontribute.rst

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,24 @@ The DCO requires a sign-off message in the following format appear on each commi
6565

6666
Signed-off-by: Firstname Lastname <[email protected]>
6767

68-
The DCO text can either be manually added to your commit body, or you can add either ``-s`` or ``--signoff`` to your usual Git commit commands. If you forget to add the sign-off you can also amend a previous commit with the sign-off by running ``git commit --amend -s``. If you’ve pushed your changes to GitHub already you’ll need to force push your branch after this with ``git push --force-with-lease``.
68+
The DCO text can either be manually added to your commit body, or you can add either ``-s`` or ``--signoff`` to your usual Git commit commands. If you forget to add the sign-off you can also amend a previous commit with the sign-off by running ``git commit --amend -s``. You can add sign-offs to multiple commits (including commits originally authored by others, if you are authorized to do so) using ``git rebase --signoff``. If you’ve pushed your changes to GitHub already you’ll need to force push your branch after this with ``git push --force-with-lease``.
69+
70+
If you want to be reminded to add the sign-off for commits in your repository, you can add the following commit-message git hook to your repository:
71+
72+
.. code:: shell
73+
74+
#!/bin/sh
75+
#
76+
# Check for DCO/Signed-off-by in message
77+
#
78+
79+
if ! grep -q "^Signed-off-by: " "$1"
80+
then
81+
echo "Aborting commit: Commit message is not signed off" >&2
82+
exit 1
83+
fi
84+
85+
Placing this script into a file called ``.git/hooks/commit-msg`` and making it executable (e.g. using ``chmod a+x .git/hooks/commit-msg`` on unixoid operating systems) will prevent commits without a sign-off.
6986

7087

7188
Reporting issues

0 commit comments

Comments
 (0)