Last active
February 4, 2019 18:37
-
-
Save cameronmalek/4353675 to your computer and use it in GitHub Desktop.
The `hooks/pre-receive` file I use for cameronmalek.com and other sites. It makes sure the working directory is clean before pushing updates, forcing the developer to commit and pull server-side updates first. It doesn't detect any staged, uncommitted files. A situation where someone stages but fails to commit a file isn't anticipated.
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
#!/bin/sh | |
export GIT_WORK_TREE=/home/cameronm/public_html/ | |
export GIT_DIR=/home/cameronm/git/cameronmalek.git | |
ec=0 | |
# test for unstaged, uncommitted files | |
git diff --exit-code &>- | |
if [ "$?" -ne 0 ]; then | |
echo "Changes not staged" | |
ec=$(($ec + 1)); | |
fi | |
# test for unadded files | |
if [ -z $(git ls-files --exclude-standard --others) ]; then | |
exit 0; | |
else | |
echo "Unadded files" | |
ec=$(($ec + 1)); | |
fi | |
exit $ec; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wow, 5 years later and I finally see this comment for the first time. These days I don't need a script like this since DevOps came around.