-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautoGit.sh
executable file
·159 lines (146 loc) · 5.58 KB
/
autoGit.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
149
150
151
152
153
154
155
156
157
158
159
#!/bin/bash
grey='\e[0m\e[90m'
GREY='\e[1m\e[90m'
red='\e[0m\e[91m'
RED='\e[1m\e[31m'
green='\e[0m\e[92m'
GREEN='\e[1m\e[32m'
yellow='\e[0m\e[93m'
YELLOW='\e[1m\e[33m'
purple='\e[0m\e[95m'
PURPLE='\e[1m\e[35m'
white='\e[0m\e[37m'
WHITE='\e[1m\e[37m'
blue='\e[0m\e[94m'
BLUE='\e[1m\e[34m'
cyan='\e[0m\e[96m'
CYAN='\e[1m\e[36m'
NC='\e[0m\e[39m'
cmd(){
echo -e ">> ${WHITE}$1${NC}";
eval $1;
echo -e;
}
echo -e -n "${BLUE}What do you want to do?${NC}\n"
echo -e -n "${YELLOW} 1,S) Status${NC}\n"
echo -e -n "${YELLOW} 2,C) Commit${NC}\n"
echo -e -n "${YELLOW} 3,B) Branch${NC}\n"
echo -e -n "${YELLOW} 4,T) Tag${NC}\n"
echo -e -n "${YELLOW} 5,X) Exit${NC}\n\n"
echo -e -n "${GREEN}(1-5)? ${NC}"
read mode
if [ "$mode" != "${mode#[1Ss]}" ] ;then
cmd "git status"
cmd "git branch -a"
elif [ "$mode" != "${mode#[2Cc]}" ] ;then
echo -e -n "${BLUE}Do you want to add, commit and push? ${GREEN}(y/n/a) ${NC}"
read answer1
if [ "$answer1" != "${answer1#[YyAa]}" ] ;then
if [ "$answer1" != "${answer1#[Aa]}" ]; then answer2='Y'; fi
# ==================================================================
# Add
# ==================================================================
if [ "$answer1" != "${answer1#[Yy]}" ]; then
echo -e -n "${BLUE}Add ${GREEN}(y/n)? ${NC}"; read answer2;
fi
if [ "$answer2" != "${answer2#[Yy]}" ] ;then
cmd "git add ."
cmd "git status"
fi
# ==================================================================
# Commit
# ==================================================================
if [ "$answer1" != "${answer1#[Yy]}" ]; then
echo -e -n "${BLUE}Commit ${GREEN}(y/n)? ${NC}"; read answer2;
fi
if [ "$answer2" != "${answer2#[Yy]}" ] ;then
if [ -s gitmessage.txt ]; then
cmd "git commit -F gitmessage.txt"
else
echo -e -n "${BLUE}Commit Message${GREEN}? ${NC}"; read answer3;
cmd "git commit -m \"${answer3}\""
fi
fi
# ==================================================================
# Push
# ==================================================================
if [ "$answer1" != "${answer1#[Yy]}" ]; then
echo -e -n "${BLUE}Push ${GREEN}(y/n)? ${NC}"; read answer2;
fi
if [ "$answer2" != "${answer2#[Yy]}" ] ;then
cmd "git push -u origin $(git branch --show-current)"
fi
# ==================================================================
# Clear commit message file
# ==================================================================
if [ -s gitmessage.txt ]; then
if [ "$answer1" != "${answer1#[Yy]}" ]; then
echo -e -n "${BLUE}Clear commit message file ${GREEN}(y/n)? ${NC}"; read answer2;
fi
if [ "$answer2" != "${answer2#[Yy]}" ] ;then
cmd "cat /dev/null > gitmessage.txt"
fi
fi
fi
elif [ "$mode" != "${mode#[3Bb]}" ] ;then
echo -e -n "${BLUE}Branch Options:\n"
echo -e -n "${YELLOW} 1) New${NC}\n"
echo -e -n "${YELLOW} 2) Switch${NC}\n"
echo -e -n "${YELLOW} 3) Switch to Master${NC}\n"
echo -e -n "${YELLOW} 4) List${NC}\n"
echo -e -n "${YELLOW} 5) Merge${NC}\n"
echo -e -n "${YELLOW} 6) Exit${NC}\n\n"
echo -e -n "${GREEN}(1-6)? ${NC}"
read answer1
if [ "$answer1" != "${answer1#[1]}" ] ;then
echo -e -n "${BLUE}New Branch Name${GREEN}? ${NC}"; read answer2;
cmd "git checkout -b ${answer2}"
cmd "git branch -a"
elif [ "$answer1" != "${answer1#[2]}" ] ;then
echo -e -n "${BLUE}Branch Name${GREEN}? ${NC}"; read answer2;
cmd "git checkout ${answer2}"
cmd "git branch -a"
elif [ "$answer1" != "${answer1#[3]}" ] ;then
cmd "git checkout master"
cmd "git branch -a"
elif [ "$answer1" != "${answer1#[4]}" ] ;then
cmd "git branch -a"
elif [ "$answer1" != "${answer1#[5]}" ] ;then
MyBranch=$(git branch --show-current);
cmd "git checkout master";
cmd "git merge ${MyBranch} --no-ff";
cmd "git push";
cmd "git branch -d ${MyBranch}";
cmd "git push origin --delete ${MyBranch}";
cmd "git branch -a"
#cmd "git remote prune origin";
#cmd "git remote prune ${MyBranch}";
fi
elif [ "$mode" != "${mode#[4Tt]}" ] ;then
echo -e -n "${BLUE}Tag Options:\n"
echo -e -n "${YELLOW} 1) New Lightweight${NC}\n"
echo -e -n "${YELLOW} 2) New Annotated${NC}\n"
echo -e -n "${YELLOW} 3) Delete${NC}\n"
echo -e -n "${YELLOW} 4) List${NC}\n"
echo -e -n "${YELLOW} 5) Exit${NC}\n\n"
echo -e -n "${GREEN}(1-5)? ${NC}"
read answer1
if [ "$answer1" != "${answer1#[1]}" ] ;then
echo -e -n "${BLUE}New Lightweight Tag Name${GREEN}? ${NC}"; read answer2;
cmd "git tag -a ${answer2}"
cmd "git show ${answer2}"
elif [ "$answer1" != "${answer1#[2]}" ] ;then
echo -e -n "${BLUE}New Annotated Tag Name${GREEN}? ${NC}"; read answer2;
cmd "git tag ${answer2}"
cmd "git show ${answer2}"
elif [ "$answer1" != "${answer1#[3]}" ] ;then
cmd "git tag"
echo -e -n "${BLUE}Tag to delete${GREEN}? ${NC}"; read answer2;
cmd "git tag -d ${answer2}"
cmd "git push origin --delete ${answer2}"
cmd "git tag"
elif [ "$answer1" != "${answer1#[4]}" ] ;then
cmd "git tag"
fi
fi
echo -e -n "${GREEN}DONE!${NC}\n\n"