Skip to content

Commit 28f8945

Browse files
committed
Make variables local using 'local' keyword in delete script
1 parent 29df065 commit 28f8945

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

git-delete-branch-interactive.sh

+16-16
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ gdel() {
1717
__gdel_usage
1818
return 1
1919
else
20-
interactive=false
20+
local interactive=false
2121
for arg in "$@"
2222
do
2323
shift
@@ -54,9 +54,9 @@ git_delete_interactive() {
5454
else
5555
__gi_check_dependencies
5656

57-
only_remote_branch=false
58-
only_local_branch=false
59-
branch_list_arg=""
57+
local only_remote_branch=false
58+
local only_local_branch=false
59+
local branch_list_arg=""
6060
for arg in "$@"
6161
do
6262
shift
@@ -73,8 +73,8 @@ git_delete_interactive() {
7373
set -- "$@" "$arg"
7474
done
7575

76-
branches=$(__gi_fetch_branches "$branch_list_arg")
77-
branch_selection_return_value="$?"
76+
local branches=$(__gi_fetch_branches "$branch_list_arg")
77+
local branch_selection_return_value="$?"
7878

7979
if [ "$#" -gt 1 ]
8080
then
@@ -88,17 +88,17 @@ git_delete_interactive() {
8888
echo "Error while fetching branches."
8989
return 1
9090
else
91-
nb_branches=$(echo $branches | wc -l)
91+
local nb_branches=$(echo $branches | wc -l)
9292
if [ "$nb_branches" -lt 1 ]
9393
then
9494
echo "No branch to delete"
9595
return 0
9696
elif [ "$nb_branches" -eq 1 ]
9797
then
98-
selected_branch=$branches
98+
local selected_branch=$branches
9999
echo "Only one branch found: $selected_branch"
100100
else
101-
selected_branch=$(echo $branches | fzf --cycle -q "$1")
101+
local selected_branch=$(echo $branches | fzf --cycle -q "$1")
102102
if [ -z "$selected_branch" ]
103103
then
104104
return 0
@@ -112,11 +112,11 @@ git_delete_interactive() {
112112
then
113113
__gdi_delete_branch --remote $selected_branch
114114
else
115-
remote_branch_info="$(__gdi_get_info_remote_branch $selected_branch)"
115+
local remote_branch_info="$(__gdi_get_info_remote_branch $selected_branch)"
116116
if [ -n "$remote_branch_info" ]
117117
then
118118
remote_branch_name="$(echo $remote_branch_info | cut -d' ' -f1)"
119-
up_to_date_with_remote="$(echo $remote_branch_info | cut -d' ' -f2)"
119+
local up_to_date_with_remote="$(echo $remote_branch_info | cut -d' ' -f2)"
120120

121121
if [ $up_to_date_with_remote = true ]
122122
then
@@ -162,11 +162,11 @@ __gdi_get_info_remote_branch() {
162162

163163
git fetch &> /dev/null
164164

165-
pattern="^\*?\s+$1"
166-
branch_info=$(git branch -vv | eval $__gi_grep_command '$pattern')
165+
local pattern="^\*?\s+$1"
166+
local branch_info=$(git branch -vv | eval $__gi_grep_command '$pattern')
167167
if [[ "$branch_info" =~ '^\*?\s+\w+\s+\w+\s+\[' ]]
168168
then
169-
remote_info="${${branch_info#*\[}%%\]*}"
169+
local remote_info="${${branch_info#*\[}%%\]*}"
170170
if [[ "$remote_info" =~ ':' ]]
171171
then
172172
echo "${remote_info%%:*} false"
@@ -177,8 +177,8 @@ __gdi_get_info_remote_branch() {
177177
}
178178

179179
__gdi_delete_branch() {
180-
local_branch=false
181-
remote_branch=false
180+
local local_branch=false
181+
local remote_branch=false
182182
for arg in "$@"
183183
do
184184
shift

utils.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ __gi_check_dependencies() {
1717
}
1818

1919
__gi_fetch_branches() {
20-
git_branch_arg=""
20+
local git_branch_arg=""
2121
for arg in "$@"
2222
do
2323
if [ "$arg" = "-r" ] || [ "$arg" = "--include-remote-branches" ]
@@ -29,7 +29,7 @@ __gi_fetch_branches() {
2929
fi
3030
done
3131

32-
branches=$(git branch $git_branch_arg | sed -r 's/^\*?\s*//')
32+
local branches=$(git branch $git_branch_arg | sed -r 's/^\*?\s*//')
3333

3434
if [ -n "$branch_filter_command" ]
3535
then

0 commit comments

Comments
 (0)