Git hook (pre-receive): commit any local changes before PUSH accepted
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 | |
# | |
# This hooks is placed in a Bare repository | |
# It makes sure that working tree doesn't contain any local changes | |
# And if it contains - submits a commit and returns false | |
# So if false returned - client should PULL and then PUSH again | |
# | |
# Assuming following file structure: | |
# . | |
# |-- myproject | |
# |-- myproject.git | |
# set WORKTREE=../myproject | |
# | |
# Where myproject.git - current bare repo and myproject - working directory | |
# To enable this hook, rename this file to "pre-receive" and make sure it is executable | |
# | |
WORKTREE=../myproject | |
GITDIR=$WORKTREE.git | |
cd $WORKTREE | |
if [ `git --work-tree=./ --git-dir=$GITDIR status | grep -c "working directory clean"` -ne 1 ]; then | |
echo "Changes detected. Issuing commit.." | |
git --work-tree=./ --git-dir=$GITDIR add . -A | |
git --work-tree=./ --git-dir=$GITDIR commit -m'Local changes commit' | |
exit 1 | |
else | |
echo "OK No local changes" | |
exit 0 | |
fi | |
# return to git directory | |
cd $GITDIR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment