Created
March 16, 2010 10:25
-
-
Save washingtontimes/333824 to your computer and use it in GitHub Desktop.
Merges a branch and tags it. Then pushes it out and deletes the branch.
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 | |
# | |
# Called as git finish-branch branch [tag] | |
# | |
# * Merges a branch into the master branch (with no-ff) | |
# * Tags the merge with either the passed tag or the date in the form MMDDYYYY | |
# * Pushes the changes to the origin repository | |
# * Deletes the branch | |
ICOUNT=1 | |
if [ -z $1 ] | |
then | |
echo "You must include a branch name." | |
exit 1 | |
else | |
if [ -z `git branch -a | grep $1` ] | |
then | |
echo "That branch name doesn't exist" | |
exit 1 | |
fi | |
BRANCH=$1 | |
fi | |
if [ -z $2 ] | |
then | |
BASE_TAG=`date "+%m%d%Y"` | |
TAGNAME=`date "+%m%d%Y"` | |
else | |
BASE_TAG=$2 | |
TAGNAME=$2 | |
if [ `git tag -l $TAGNAME` ] | |
then | |
echo "$TAGNAME already is a tag in this repository, please enter a different tag." | |
exit 1 | |
fi | |
fi | |
tag_exists() { | |
if [ `git tag -l $TAGNAME` ] | |
then | |
return 0 #true | |
else | |
return 1 #false | |
fi | |
} | |
get_unique_tag() { | |
if tag_exists | |
then | |
TAGNAME=`expr "$BASE_TAG-1"` | |
while tag_exists | |
do | |
((ICOUNT++)) | |
TAGNAME=`expr "$BASE_TAG-$ICOUNT"` | |
done | |
fi | |
} | |
echo "Switching to the master branch..." | |
git checkout master | |
echo "Updating the master branch..." | |
git pull --tags origin master | |
echo "Checking the tag..." | |
get_unique_tag | |
echo "Using tag: $TAGNAME" | |
echo "Merging branch $BRANCH into master..." | |
git merge --no-ff $BRANCH | |
git tag -a $TAGNAME | |
echo "Deleting branch $BRANCH..." | |
git branch -d $BRANCH | |
echo "Pushing" | |
git push --all origin master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment