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 hidden or 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; |
Very nice and just what I was looking for ;-)
Would be interesting to see the "staged, but not committed files"-check added as well for completeness
``git diff --staged`Another idea I'm playing with is to get the script to commit any changes before exiting and stopping the push, so the repo is "pull-ready" for the developer to merge the changes.
What are your thoughts on that ?
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very nice and just what I was looking for ;-)
Would be interesting to see the "staged, but not committed files"-check added as well for completeness
``git diff --staged`
Another idea I'm playing with is to get the script to commit any changes before exiting and stopping the push, so the repo is "pull-ready" for the developer to merge the changes.
What are your thoughts on that ?