6

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.
#
2
  • Should it warn on each commit, or only on a push?
    – choroba
    Mar 8, 2019 at 10:18
  • On the current branch? Or the current commit? Maybe use run a git diff of the file from HEAD to the merge base? Mar 8, 2019 at 10:32

1 Answer 1

6

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

1
  • Thanks for the note on how they are not included in the repo, I've made a script to install the hooks. Mar 8, 2019 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.