-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_acp.sh
148 lines (126 loc) · 3.82 KB
/
git_acp.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash/
#############################################################################
# COMMENT TO ADD TO THE GIT COMMIT COMMAND
#############################################################################
COMMENT=""
BRANCH=`git rev-parse --abbrev-ref HEAD`
TAG=""
SHOW_TAGS=`git tag --list`
MASTER="master"
DEV="dev"
IS_TAG_CURRENT=1
#############################################################################
# COMMAND TO ADD TAG
#############################################################################
add_tag(){
wait
echo "All available tags:"
echo $SHOW_TAGS
wait
git tag $TAG
}
#############################################################################
# COMMAND TO DO PUSH
#############################################################################
execute_push(){
wait
git push -u origin ${BRANCH}
}
#############################################################################
# COMMAND TO DO ADD AND COMMIT OF THE FILES
#############################################################################
execute_add_commit(){
wait
git add -A
wait
git commit -m "${COMMENT}"
}
#############################################################################
# COMMAND TO DO PUSH WITH TAG
#############################################################################
execute_push_with_tag(){
wait
git push -u origin ${BRANCH} ${TAG}
}
#############################################################################
# FUNCTION TO CHANGE THE BRANCH AND DO THE MERGE
#############################################################################
execute_merge(){
wait
git checkout $1
wait
git merge ${BRANCH}
}
if [[ $# -eq 0 ]]; then
echo -e "\e[33mWarning: you have not specified the commit message\e[0m"
CURRENT_BRANCH=`git branch -a`
echo -e "\e[32mCURRENT BRANCH: ${CURRENT_BRANCH}\e[0m"
while [ -z "${COMMENT}" -a "$COMMENT" == "" ]; do
read -p "Please enter the commit message:" comment
COMMENT=\"${comment}\"
done
else
COMMENT=\"$1\"
fi
#############################################################################
# ASK FOR MERGE AND TAG IF NECESSARY
#############################################################################
read -p "Want to do a merge?[Y/n]" merge
read -p "Want to add a tag?[Y/n]" tag
if [ $tag == "Y" -o $tag == "y" ]; then
read -p "Enter the tag name:" new_tag
TAG=$new_tag
fi
if [ $merge == "Y" -o $merge == "y" ]; then
read -p "Insert the branch that you want to merge with the current:" branch_to_merge
if [ $tag == "Y" -o $tag == "y" ]; then
read -p "Tag commit of current or merge branch?[c=current branch/m=merge branch]" cm
# FAKING TERNARY OPERATOR... REMEMBER 0 IS TRUE
IS_TAG_CURRENT=$cm
if [ $IS_TAG_CURRENT == "c" ]; then
execute_add_commit
add_tag
execute_push_with_tag
BRANCH=`git rev-parse --abbrev-ref HEAD`
execute_merge $branch_to_merge
execute_add_commit
execute_push
echo "certo che sono qua"
else
execute_add_commit
execute_push
BRANCH=`git rev-parse --abbrev-ref HEAD`
execute_merge $branch_to_merge
execute_add_commit
add_tag
execute_push_with_tag
fi
else
execute_add_commit
execute_push
execute_merge $branch_to_merge
execute add_commit
execute_push
fi
else
execute_add_commit
if [ $tag == "Y" -o $tag == "y" ]; then
add_tag
execute_push_with_tag
else
execute_push
fi
fi
#############################################################################
# ASK USER IF WANT TO CHECKOUT TO THE DEV BRANCH
#############################################################################
BRANCH=`git rev-parse --abbrev-ref HEAD`
if [ $BRANCH == $MASTER ]; then
read -p "Want to checkout to dev?[Y/n]:" yn
if [ $yn == "Y" -o $yn == "y" ]; then
git checkout $DEV
fi
fi
# FINISH
##############################################################################
echo -e "\e[32mGIT ADDED, COMMITTED AND PUSHED"