Skip to content

Instantly share code, notes, and snippets.

@nandub
Forked from patrickkettner/prepare-commit-msg
Last active July 19, 2016 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nandub/520339a6434aa7ee5d794f8fe98b6583 to your computer and use it in GitHub Desktop.
Save nandub/520339a6434aa7ee5d794f8fe98b6583 to your computer and use it in GitHub Desktop.
This git hook appends "[ci skip]" to your commit message if the readme file is the only thing being touched. Read more about it here - http://about.travis-ci.org/docs/user/how-to-skip-a-build/
#!/usr/bin/env bash
# a list of all files that are changing with this commit
FILES_CHANGING=$(git diff --cached --name-only --diff-filter=ACM)
# if there is only one file changing
if [ $(echo "$FILES_CHANGING" | wc -l) -eq 1 ]; then
# and that file is a readme
README_CHANGING=$(echo $FILES_CHANGING | grep -Ei "readme(.md|.txt)?$")
if [ -n $README_CHANGING ]; then
# append it to $1 - the file containing the commit message
echo " [ci skip]" >> $1
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment