Created
March 29, 2018 19:38
-
-
Save AbeEstrada/c753c22295fba479f2c95edbcf303036 to your computer and use it in GitHub Desktop.
Git `post-receive` script
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/bash | |
BASE=/var/www/domain.com | |
while read oldrev newrev refname | |
do | |
branch=$(git rev-parse --symbolic --abbrev-ref $refname) | |
commit=$(git rev-parse --short HEAD) | |
BRANCH_DIR="$BASE/$branch" | |
BRANCH_TEMP_DIR="$BASE/$branch.temp" | |
rm -rf $BRANCH_TEMP_DIR | |
cp -r $BRANCH_DIR $BRANCH_TEMP_DIR || mkdir -p $BRANCH_TEMP_DIR | |
cd $BRANCH_TEMP_DIR | |
git --work-tree=$BRANCH_TEMP_DIR --git-dir=$BASE/repository.git checkout $branch -f | |
# run your custom commands here | |
rm -rf $BRANCH_DIR | |
mv $BRANCH_TEMP_DIR $BRANCH_DIR | |
echo "$commit" > "$BRANCH_DIR/current" | |
echo "Done!" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment