forked from codeenigma/ce-contrib-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare_branch.sh
executable file
·88 lines (78 loc) · 1.91 KB
/
prepare_branch.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
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
88
#!/bin/bash
# Script to prepare a working feature branch
set -e
usage(){
echo 'prepare_branch.sh [OPTIONS]'
echo 'Prepare feature branch for working with.'
echo ''
echo 'Available options:'
echo '--name: Name of the feature branch to create or refresh'
echo '--default: Name of the default branch, 1.x, 2.x, apply, etc.'
echo '--remote: Defaults to origin, allows you to set an alternative remote name'
}
# Set defaults
REMOTE="origin"
DEFAULT="2.x"
# Parse options arguments.
parse_options(){
while [ "${1:-}" ]; do
case "$1" in
"--name")
shift
NAME="$1"
;;
"--default")
shift
DEFAULT="$1"
;;
"--remote")
shift
REMOTE="$1"
;;
*)
usage
exit 1
;;
esac
shift
done
}
# Parse options.
echo "Parsing provided options."
parse_options "$@"
# Check we received a feature branch name
if [ -z "$NAME" ]; then
echo "You must provide a branch name. Exiting."
exit 1
fi
# Fetch branches
git_branches=`git branch`
# Determine naming convention applied
if [[ $git_branches == *"$DEFAULT"* ]]; then
echo "Using devel/$DEFAULT naming convention."
elif [[ $git_branches == *"apply"* ]]; then
echo "Using apply/test naming convention."
DEFAULT="apply"
else
echo "Unable to determine the default branch name. Exiting."
exit 1
fi
echo "NOW EXECUTING GIT COMMANDS!"
echo "---------------------------"
echo "Making sure main branch is up to date."
# Checkout and pull main branch
git checkout $DEFAULT
git pull $REMOTE $DEFAULT
echo "---------------------------"
echo "Preparing feature branch."
# Determine if feature branch exists
if [[ `git branch --list $NAME` ]]; then
echo "Branch name with $NAME already exists."
git checkout $NAME
git merge $DEFAULT
else
echo "No branch with name $NAME, creating."
git checkout -b $NAME
fi
echo "---------------------------"
echo "ALL DONE!"