tangled
alpha
login
or
join now
hatixntsoa.tngl.sh
/
source.controller
1
fork
atom
Simple Git & GitHub CLI Shell Scripts
1
fork
atom
overview
issues
pulls
pipelines
refactor[gbd]: Cleaner code
Hatix Ntsoa
1 year ago
152f9a6f
66b4b008
+103
-94
1 changed file
expand all
collapse all
unified
split
gh_scripts
gbd.sh
+103
-94
gh_scripts/gbd.sh
reviewed
···
17
17
if [ $# -eq 1 ]; then
18
18
if [ "$1" = "$default_branch" ]; then
19
19
echo "${BOLD} Fatal ! Cannot Delete the Default Branch "
20
20
-
elif ! git show-ref --verify --quiet "refs/heads/$1" &>/dev/null; then
20
20
+
return 0
21
21
+
fi
22
22
+
23
23
+
if ! git show-ref --verify --quiet "refs/heads/$1" &>/dev/null; then
21
24
echo "${BOLD} Fatal ! Branch ${GREEN}$1 ${RESET_COLOR}doesn't exist ${RESET}"
22
22
-
else
23
23
-
# this to check if we want to delete the remote branch too
24
24
-
check_delete_remote_branch() {
25
25
-
if [ "$current_branch" = "$default_branch" ]; then
26
26
-
echo "${BOLD} Fatal ! Cannot Delete the Default Branch "
27
27
-
else
28
28
-
printf "${BOLD}${RESET_COLOR}Delete remote branch${GREEN} "$current_branch"${RESET_COLOR} ? (y/n) ${RESET}"
29
29
-
read delete_remote_branch
30
30
-
echo ${RESET}
31
31
-
if [ "$delete_remote_branch" = "y" ]; then
32
32
-
git push origin --delete "$current_branch"
33
33
-
elif [ "$delete_remote_branch" = "n" ]; then
34
34
-
return 0
35
35
-
else
36
36
-
check_delete_remote_branch
37
37
-
fi
38
38
-
fi
39
39
-
}
25
25
+
return 0
26
26
+
fi
40
27
41
41
-
check_delete_branch() {
42
42
-
branch_name="$1"
28
28
+
# this to check if we want to delete the remote branch too
29
29
+
check_delete_remote_branch() {
30
30
+
if [ "$current_branch" = "$default_branch" ]; then
31
31
+
echo "${BOLD} Fatal ! Cannot Delete the Default Branch "
32
32
+
return 0
33
33
+
fi
34
34
+
35
35
+
printf "${BOLD}${RESET_COLOR}Delete remote branch${GREEN} "$current_branch"${RESET_COLOR} ? (y/n) ${RESET}"
36
36
+
read delete_remote_branch
37
37
+
echo ${RESET}
38
38
+
39
39
+
if [ "$delete_remote_branch" = "y" ]; then
40
40
+
git push origin --delete "$current_branch"
41
41
+
elif [ "$delete_remote_branch" = "n" ]; then
42
42
+
return 0
43
43
+
else
44
44
+
check_delete_remote_branch
45
45
+
fi
46
46
+
}
43
47
44
44
-
printf "${BOLD}${RESET_COLOR}Delete branch${GREEN} "$branch_name"${RESET_COLOR} ? (y/n) ${RESET}"
45
45
-
read delete_branch
48
48
+
check_delete_branch() {
49
49
+
branch_name="$1"
50
50
+
51
51
+
printf "${BOLD}${RESET_COLOR}Delete branch${GREEN} "$branch_name"${RESET_COLOR} ? (y/n) ${RESET}"
52
52
+
read delete_branch
46
53
47
47
-
if [ "$delete_branch" = "y" ]; then
48
48
-
if [ "$current_branch" != "$default_branch" ]; then
49
49
-
git checkout $default_branch >/dev/null 2>&1
50
50
-
fi
54
54
+
if [ "$delete_branch" = "y" ]; then
55
55
+
if [ "$current_branch" != "$default_branch" ]; then
56
56
+
git checkout $default_branch >/dev/null 2>&1
57
57
+
fi
51
58
52
52
-
if has_remote; then
53
53
-
repo_url=$(git config --get remote.origin.url)
54
54
-
repo_owner=$(echo "$repo_url" | awk -F '[/:]' '{print $(NF-1)}')
59
59
+
if has_remote; then
60
60
+
repo_url=$(git config --get remote.origin.url)
61
61
+
repo_owner=$(echo "$repo_url" | awk -F '[/:]' '{print $(NF-1)}')
55
62
56
56
-
# check if we are not the owner of the repo
57
57
-
if [ "$repo_owner" == "$current_user" ]; then
58
58
-
is_remote_branch=$(git branch -r | grep "origin/$1")
59
59
-
if [ -n "$is_remote_branch" ]; then
60
60
-
# prompt for sudo
61
61
-
# password if required
62
62
-
allow_sudo
63
63
+
# check if we are not the owner of the repo
64
64
+
if [ "$repo_owner" == "$current_user" ]; then
65
65
+
is_remote_branch=$(git branch -r | grep "origin/$1")
66
66
+
if [ -n "$is_remote_branch" ]; then
67
67
+
# prompt for sudo
68
68
+
# password if required
69
69
+
allow_sudo
63
70
64
64
-
# Check for internet connectivity to GitHub
65
65
-
if $SUDO ping -c 1 github.com &>/dev/null; then
66
66
-
check_delete_remote_branch
67
67
-
fi
71
71
+
# Check for internet connectivity to GitHub
72
72
+
if $SUDO ping -c 1 github.com &>/dev/null; then
73
73
+
check_delete_remote_branch
68
74
fi
69
75
fi
70
70
-
fi
71
71
-
git branch -D "$1"
72
72
-
elif [ "$delete_branch" = "n" ]; then
73
73
-
return 0
74
74
-
else
75
75
-
check_delete_branch $branch_name
76
76
+
fi
76
77
fi
77
77
-
}
78
78
-
check_delete_branch $1
79
79
-
fi
78
78
+
79
79
+
git branch -D "$1"
80
80
+
elif [ "$delete_branch" = "n" ]; then
81
81
+
return 0
82
82
+
else
83
83
+
check_delete_branch $branch_name
84
84
+
fi
85
85
+
}
86
86
+
87
87
+
check_delete_branch $1
80
88
elif [ $# -eq 0 ]; then
81
89
if [ "$current_branch" = "$default_branch" ]; then
82
90
echo "${BOLD}${RESET_COLOR} Fatal ! Cannot Delete the Default Branch "
83
83
-
else
84
84
-
check_delete_branch() {
85
85
-
printf "${BOLD}${RESET_COLOR}Delete branch${GREEN} "$current_branch"${RESET_COLOR} ? (y/n) ${RESET}"
86
86
-
read delete_branch
87
87
-
if [ "$delete_branch" = "y" ]; then
88
88
-
# TODO : Remote branch Deletion
89
89
-
check_delete_remote_branch() {
90
90
-
if [ "$current_branch" = "$default_branch" ]; then
91
91
-
echo "${BOLD}${RESET_COLOR} Fatal ! Cannot Delete the Default Branch "
91
91
+
return 0
92
92
+
fi
93
93
+
94
94
+
check_delete_branch() {
95
95
+
printf "${BOLD}${RESET_COLOR}Delete branch${GREEN} "$current_branch"${RESET_COLOR} ? (y/n) ${RESET}"
96
96
+
read delete_branch
97
97
+
if [ "$delete_branch" = "y" ]; then
98
98
+
# TODO : Remote branch Deletion
99
99
+
check_delete_remote_branch() {
100
100
+
if [ "$current_branch" = "$default_branch" ]; then
101
101
+
echo "${BOLD}${RESET_COLOR} Fatal ! Cannot Delete the Default Branch "
102
102
+
else
103
103
+
printf "${BOLD}${RESET_COLOR}Delete remote branch${GREEN} "$current_branch"${RESET_COLOR} ? (y/n) ${RESET}"
104
104
+
read delete_remote_branch
105
105
+
echo ${RESET}
106
106
+
if [ "$delete_remote_branch" = "y" ]; then
107
107
+
git push origin --delete "$current_branch"
108
108
+
elif [ "$delete_remote_branch" = "n" ]; then
109
109
+
return 0
92
110
else
93
93
-
printf "${BOLD}${RESET_COLOR}Delete remote branch${GREEN} "$current_branch"${RESET_COLOR} ? (y/n) ${RESET}"
94
94
-
read delete_remote_branch
95
95
-
echo ${RESET}
96
96
-
if [ "$delete_remote_branch" = "y" ]; then
97
97
-
git push origin --delete "$current_branch"
98
98
-
elif [ "$delete_remote_branch" = "n" ]; then
99
99
-
return 0
100
100
-
else
101
101
-
check_delete_remote_branch
102
102
-
fi
111
111
+
check_delete_remote_branch
103
112
fi
104
104
-
}
113
113
+
fi
114
114
+
}
105
115
106
106
-
git checkout "$default_branch" >/dev/null 2>&1
116
116
+
git checkout "$default_branch" >/dev/null 2>&1
107
117
108
108
-
if has_remote; then
109
109
-
repo_url=$(git config --get remote.origin.url)
110
110
-
repo_owner=$(echo "$repo_url" | awk -F '[/:]' '{print $(NF-1)}')
118
118
+
if has_remote; then
119
119
+
repo_url=$(git config --get remote.origin.url)
120
120
+
repo_owner=$(echo "$repo_url" | awk -F '[/:]' '{print $(NF-1)}')
111
121
112
112
-
# check if we are not the owner of the repo
113
113
-
if [ "$repo_owner" == "$current_user" ]; then
114
114
-
is_remote_branch=$(git branch -r | grep "origin/$current_branch")
115
115
-
116
116
-
if [ -n "$is_remote_branch" ]; then
117
117
-
# prompt for sudo
118
118
-
# password if required
119
119
-
allow_sudo
122
122
+
# check if we are not the owner of the repo
123
123
+
if [ "$repo_owner" == "$current_user" ]; then
124
124
+
is_remote_branch=$(git branch -r | grep "origin/$current_branch")
125
125
+
126
126
+
if [ -n "$is_remote_branch" ]; then
127
127
+
# prompt for sudo
128
128
+
# password if required
129
129
+
allow_sudo
120
130
121
121
-
# Check for internet connectivity to GitHub
122
122
-
if $SUDO ping -c 1 github.com &>/dev/null; then
123
123
-
check_delete_remote_branch
124
124
-
fi
131
131
+
# Check for internet connectivity to GitHub
132
132
+
if $SUDO ping -c 1 github.com &>/dev/null; then
133
133
+
check_delete_remote_branch
125
134
fi
126
135
fi
127
136
fi
128
128
-
git branch -D "$current_branch"
129
129
-
elif [ "$delete_branch" = "n" ]; then
130
130
-
return 0
131
131
-
else
132
132
-
check_delete_branch
133
137
fi
134
134
-
}
135
135
-
check_delete_branch
136
136
-
fi
138
138
+
git branch -D "$current_branch"
139
139
+
elif [ "$delete_branch" = "n" ]; then
140
140
+
return 0
141
141
+
else
142
142
+
check_delete_branch
143
143
+
fi
144
144
+
}
145
145
+
check_delete_branch
137
146
else
138
147
echo "${BOLD}${RESET_COLOR} Usage : gbd branch_to_delete"
139
148
fi