Created
May 9, 2013 06:52
-
-
Save un1ko85/5545989 to your computer and use it in GitHub Desktop.
Git: extract branch name in post update hook
But if branch was deleted (for example by git push origin :branch-name), you will receive errors from this command, so I think it’s safer to use another method:
As post-update hook receives branch’s path as first parameter (something like refs/heads/branch-name), you can extract the branch name using …
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
branch=$(git rev-parse --symbolic --abbrev-ref $1) | |
branch=$(echo $1 | awk -F'/' '{print $3}') | |
if [ ! -f $1 ]; then | |
echo "Branch $branch was deleted! Do something then.." | |
else | |
echo "Branch $branch was updated! Do something then.." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment