forked from coordt/git-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-finish-branch
executable file
·87 lines (79 loc) · 1.74 KB
/
git-finish-branch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/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
set -e
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 "Rebasing the branch onto current master..."
git checkout $BRANCH
git rebase master
git checkout 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 -m"Release $TAGNAME"
echo "Deleting branch $BRANCH..."
git branch -D $BRANCH
if git branch -r | grep -q $BRANCH
then
echo "Deleting remote branch $BRANCH..."
git branch -d -r origin/$BRANCH
git push origin :$BRANCH
fi
echo "Pushing"
git push --all
git push --tags