-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-broom
More file actions
209 lines (185 loc) · 5.09 KB
/
Copy pathgit-broom
File metadata and controls
209 lines (185 loc) · 5.09 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/bin/bash
#
# A swiss knife to git branches, managing easily the local and remote copy
# This file should be called from a git repo where the maintenance is
#
# A proposed use:
# Copy this file into /usr/local/bin/
#
# ln -s /usr/local/bin/git-broom /usr/bin/git-broom
#
#
# @author: Imre von Geczy
# @date: 2016 March 09
#
################################################
current=`git rev-parse --abbrev-ref HEAD`
deleteLocal () {
item=$1
echo
echo -e "\x1B[01;95mLocal Delete:\x1B[0m \x1B[01;96m$item \x1B[0m"
echo
echo -e "\x1B[01;91mDo you want to delete on the Local? \x1B[0m"
read -r -p "Are you sure? [y/N] " response
case $response in
[yY][eE][sS]|[yY])
git branch -D $item
echo -e "Deleted: \x1B[01;93m $item \x1B[0m"
;;
*)
echo -e "\x1B[01;92mNot removed \x1B[0m"
;;
esac
}
deleteRemote () {
item=$1
echo
echo -e "\x1B[01;93mRemote Delete:\x1B[0m \x1B[01;96m$item \x1B[0m"
echo
echo -e "\x1B[01;91mDo you want to delete on the git Server? \x1B[0m"
read -r -p "Are you sure? [y/N] " response
case $response in
[yY][eE][sS]|[yY])
git push origin --delete $item
echo -e "Deleted: \x1B[01;93m $item \x1B[0m"
;;
*)
echo -e "\x1B[01;92mNot removed \x1B[0m"
;;
esac
}
deleteBoth () {
item=$1
echo
echo -e "\x1B[01;92mBoth Delete:\x1B[0m \x1B[01;96m$item \x1B[0m"
echo
echo -e "\x1B[01;91mDo you want to delete on the git Server and on the Local? \x1B[0m"
read -r -p "Are you sure? [y/N] " response
case $response in
[yY][eE][sS]|[yY])
git branch -D $item
git push origin :$item
echo -e "Deleted: \x1B[01;93m $item \x1B[0m"
;;
*)
echo -e "\x1B[01;92mNot removed \x1B[0m"
;;
esac
}
deleteManager () {
current=$1
branch=$2
name=$3
date=$4
fdate=$5
if [[ $item != $current &&
$item != "EPIC"* &&
$item != "dev_trunk"* &&
$item != "test_trunk"* &&
$item != "uat"* &&
$item != "master"* ]]; then
echo
echo -e "Branch: \x1B[01;96m$branch \x1B[0m"
echo "Name: $name"
echo "Update: $fdate"
echo "Date: $date"
echo
echo -e "\x1B[01;91mWhere do you want to delete? \x1B[0m"
echo -e "[\x1B[01;95mL\x1B[0m]ocal [\x1B[01;93mR\x1B[0m]emote [\x1B[01;92mB\x1B[0m]oth [\x1B[01;97mS\x1B[0m]kip [\x1B[01;97mQ\x1B[0m]uit "
read -r response
case $response in
[lL])
# Local Delete
deleteLocal $branch
;;
[rR])
# Remote Delete
deleteRemote $branch
;;
[bB])
# Both, Remote-Local Delete
deleteBoth $branch
;;
[qQ])
echo -e "Quit"
return 1
;;
[sS])
echo -e "\x1B[01;92mStep forward \x1B[0m"
;;
esac
fi
return 0
}
pruneDry () {
echo "These local branches don’t exist on the server anymore"
git remote prune origin --dry-run
echo "Done! Step forward by Enter key"
read
}
pruneList() {
echo "Remove local branches which don’t exist on the server anymore"
git remote prune origin
echo "Done! Step forward by Enter key"
read
}
deleteBranches() {
local current=$1
local response=0
echo "Git branch list with authors and date"
echo -e "\x1B[01;96mYou are in branch\x1B[0m: $current"
local remoteBranch=($(git ls-remote --heads | grep -v origin))
local author=($(git config user.name))
for item in ${remoteBranch[*]}
do
IFS="/"
read -a array <<< "$item"
local branch="${array[2]}"
if [[ -n $branch ]]; then
result=($(git show --format="%ai|%ar|%an" origin/$branch | head -n 1))
IFS="|"
details=($result)
name=${details[2]}
date=${details[0]}
fdate=${details[1]}
if [[ $name =~ $author ]]; then
echo "======================================================"
deleteManager $current $branch $name $date $fdate
local response=$?
fi
fi
if [[ $response -eq 1 ]]; then
echo "Exit here $response"
return 0
fi
done
unset remoteBranch
read
}
start () {
current=$1
while true; do
echo -e "1) Check what local branches do not exist on the server"
echo -e "2) Clean your local list"
echo -e "3) Delete Branches"
echo -e "x) Exit"
read -r -p "Select Options [1/2/3/q] " response
echo
case $response in
[1])
pruneDry
;;
[2])
pruneList
;;
[3])
deleteBranches $current
;;
[qQ])
exit;
;;
esac
clear
done
}
start $current