-
Notifications
You must be signed in to change notification settings - Fork 2
/
git-merge-branch
executable file
·75 lines (66 loc) · 1.4 KB
/
git-merge-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
#!/bin/bash
#
# Called as git merge-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
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 "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 "Pushing"
git push --all
git push --tags