Last active
November 2, 2016 06:57
-
-
Save janosgyerik/5725039 to your computer and use it in GitHub Desktop.
A post-receive hook that runs a script if changes were pushed to a specific branch. (Hook scripts are in the hooks/ directory of a Git repository, and must be executable.)
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 | |
# 1. Create symlinks to the real upgrade scripts for each branch, for example: | |
# ./upgrade-beta.sh # will only be called when "beta" branch is updated | |
# ./upgrade-prod.sh # will only be called when "prod" branch is updated | |
# | |
# 2. Put these symlinks in the repository root, NOT in the hooks/ directory | |
# the post-receive hook receives parameters on stdin | |
while read oldrev newrev refname | |
do | |
branch=$(git rev-parse --symbolic --abbrev-ref $refname) | |
upgrade_sh=./upgrade-$branch.sh | |
if test -e $upgrade_sh; then | |
upgrade_sh=$(readlink $upgrade_sh || echo $upgrade_sh) | |
echo calling upgrade script: $upgrade_sh | |
$upgrade_sh | |
else | |
echo NOT calling non-existent upgrade script: $upgrade_sh | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment