-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaddBranch.sh
98 lines (81 loc) · 1.85 KB
/
addBranch.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
89
90
91
92
93
94
95
96
97
98
# !/bin/bash
######################
# bash addBranch.sh branch task
# $1 - branch (dev, release, held and etc)
# $2 - task (on Jira, on your task manager and etc)
######################
### funcs
#
require_name_arg() {
if [ -z $1 ]; then
echo "Missing argument BASE BRANCH NAME"
exit 0
elif [ -z $2 ]; then
echo "Missing argument TASK NAME"
exit 0
else
echo ""
fi
}
contains() {
branches=$(git branch -a)
for b in $branches
do
if [ $b == $1 ]; then
echo "FOUND"
echo true
break
fi
done;
echo false
#[[ $branches =~ (^|[[:space:]])$1($|[[:space:]]) ]] && true || false
}
#
#
### testing
#
require_name_arg $1 $2
#
### variables
#
#
USERNAME=$(id -u -n)
BRANCH=$1
TASK=$2
CURRENT_BRANCH=$(git branch --show-current | grep "^$PREFIX")
if [ CURRENT_BRANCH != BRANCH ]; then
read -p "Created brach is different then current_branch. Do you want to continue (yes / no)?" answ
case $answ in
[Yy]* ) echo "Continue..."; ;;
[Nn]* ) exit 0;;
* ) echo "Please answer yes or no";;
esac
fi
######################
STATUS=$(contains $BRANCH)
#echo STATUS
if [ -n $STATUS ]; then
echo ""
echo "No branch name exist into DE git flow pattern"
echo "You can start a new feature branch:"
echo ""
echo " git checkout -b BRANCH_NAME"
exit 0
fi
# create branch
git checkout -b "$BRANCH-$TASK"
# update branch variable
CURRENT_BRANCH=$(git branch --show-current | grep "^$PREFIX")
# setup the local branch clone for the first time
git fetch -q "$BRANCH" "$CURRENT_BRANCH"
git branch --no-track "$CURRENT_BRANCH" FETCH_HEAD
git pull origin "$BRANCH"
echo "Created local branch $BRANCH based on $REMOTE's $BRANCH."
echo
echo "Summary of actions:"
echo "- A new branch '$BRANCH-$TASK' was created, based on '$BRANCH'"
echo "- You are now on branch '$BRANCH-$TASK'"
echo ""
echo "Now, start committing."
echo ""
exit 0