Skip to content

Instantly share code, notes, and snippets.

@patrickkettner
Last active July 19, 2016 22:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save patrickkettner/7328297 to your computer and use it in GitHub Desktop.
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/
#!/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
@nandub
Copy link

nandub commented Jul 19, 2016

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)?$")

@nandub
Copy link

nandub commented Jul 19, 2016

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