Stuart Axon
Stuart Axon

Reputation: 1874

git hook to warn if changelog not updated?

How can I write a git hook that outputs a warning in the comment section if there have been no commits to CHANGELOG on the current branch ?

I would like to output something like:

# CHANGELOG Not updated.
#
# Update changelog before submitting PR.
#

Upvotes: 6

Views: 1083

Answers (1)

wiomoc
wiomoc

Reputation: 1089

If you want a local commit hook, you can add this script under .git/hooks/pre-commit

#!/bin/bash
if git status -s | grep -q "M CHANGELOG"; then
    exit 0
else
    echo "# CHANGELOG Not updated."
    exit 1
fi

Please notice that commit hooks are not versioned nor included in the repository

Upvotes: 6

Related Questions