Skip to content

Instantly share code, notes, and snippets.

@balibou
Created January 1, 2018 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save balibou/e7e294865324936322bc7d296d83a914 to your computer and use it in GitHub Desktop.
Save balibou/e7e294865324936322bc7d296d83a914 to your computer and use it in GitHub Desktop.
posthotfix.sh
#!/bin/bash
# this script will merge the hotfix branch
# checks if branch has something pending
function parse_git_dirty() {
git diff --quiet --ignore-submodules HEAD 2>/dev/null; [ $? -eq 1 ] && echo "*"
}
# gets the current git branch
function parse_git_branch() {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/"
}
# get last commit
function parse_git_hash() {
git rev-parse --short HEAD 2> /dev/null | sed "s/\(.*\)//"
}
# get last commit without 'hotfix-' string
function parse_commit() {
echo $GIT_BRANCH | sed 's/.*hotfix-\([^ ]*\).*/\1/'
}
GIT_BRANCH=$(parse_git_branch)$(parse_git_hash)
GIT_VERSION=$(parse_commit)
# checkout on master branch, merge and tag
git checkout master
git merge --no-ff $GIT_BRANCH
echo "Tagging version : $GIT_VERSION"
git tag -a -m "Tagging version $GIT_VERSION" "v$GIT_VERSION"
# push on master and tags
git push origin master -f # if you want to push on master as well
git push origin --tags
# ask for deleting hotfix-branch
read -p "Do you want to delete $GIT_BRANCH branch? [y]" RESPONSE
if [ "$RESPONSE" = "" ]; then RESPONSE="y"; fi
if [ "$RESPONSE" = "y" ]; then
git branch -d $GIT_BRANCH
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment