-
Notifications
You must be signed in to change notification settings - Fork 0
/
master_merge.sh
executable file
·57 lines (48 loc) · 1.06 KB
/
master_merge.sh
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
#!/bin/bash
#
# Pull the latest and merge current branch with master
#
verbose=""
target_branch=""
usage() {
echo "Merge with master the current or specified branch"
echo "usage: `basename $0` [-h][-v] -b <branch-name>"
echo ""
exit 1
}
while getopts "hvb:" option; do
case "${option}" in
h)
usage
;;
v)
verbose=" -v"
;;
b)
target_branch=$OPTARG
;;
\?)
usage
;;
:)
echo "Error: -${OPTARG} requires an argument."
usage
;;
esac
done
# get the current branch
curr_branch=$(eval "git rev-parse --abbrev-ref HEAD")
# Get the current branch, if needed
if [ "${target_branch}" == "" ]; then
if [ "${curr_branch}" == "master" ]; then
echo "Already on master"
exit 1
fi
else
curr_branch="${target_branch}"
fi
# do the work
eval "git checkout master && git pull --rebase"
eval "git checkout ${curr_branch}"
result=$(eval "git merge ${verbose} master")
exit "$?"