Last active
July 19, 2016 22:23
-
-
Save patrickkettner/7328297 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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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=$($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 |
This is the error I get when committing without the fix:
.git/hooks/prepare-commit-msg: line 12: README.md: command not found
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found this hook very use full, tire of doing it by hand. I found an error:
README_CHANGING=$($FILES_CHANGING | grep -Ei "readme(.md|.txt)?$")
should be
README_CHANGING=$(echo $FILES_CHANGING | grep -Ei "readme(.md|.txt)?$")