Skip to content

Commit b1bd258

Browse files
committed
Implement 'local only' flag
1 parent 2199b35 commit b1bd258

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

git-delete-branch-interactive.sh

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ gdel() {
4040

4141
__gdi_usage() {
4242
echo "Git Delete Interactive -- SimGus 2020"
43-
echo "Usage: git_delete_interactive [-r] [<PARTIAL-BRANCH-NAME>]"
43+
echo "Usage: git_delete_interactive [-l|-r] [<PARTIAL-BRANCH-NAME>]"
4444
echo "\t<PARTIAL-BRANCH-NAME>\t\tA pattern to look for in the branches names (filters out other branches)"
45-
echo "\t-r, --include-remote-branches\tIf the command runs interactively, only takes into account the remote branches"
46-
echo "\t-a, --all\t\t\tIf the command runs interactively, take into account both the local and remote branches"
45+
echo "\t-l, --local-only\tOnly allows to select and delete a local branch"
46+
echo "\t-r, --remote-only\tOnly allows to select and delete a remote branch"
4747
}
4848
git_delete_interactive() {
4949
echo "git delete interactive called with params $@"
@@ -54,20 +54,28 @@ git_delete_interactive() {
5454
else
5555
__gi_check_dependencies
5656

57-
branches=$(__gi_fetch_branches $@)
58-
branch_selection_return_value="$?"
59-
60-
delete_remote_branch=false
57+
only_remote_branch=false
58+
only_local_branch=false
59+
branch_list_arg=""
6160
for arg in "$@"
6261
do
6362
shift
64-
if [ "$arg" = "-r" ] || [ "$arg" = "--remote-branch" ]
63+
if [ "$arg" = "-r" ] || [ "$arg" = "--remote-only" ]
64+
then
65+
only_remote_branch=true
66+
branch_list_arg="-r"
67+
continue
68+
elif [ "$arg" = "-l" ] || [ "$arg" = "--local-only" ]
6569
then
66-
delete_remote_branch=true
70+
only_local_branch=true
71+
continue
6772
fi
6873
set -- "$@" "$arg"
6974
done
7075

76+
branches=$(__gi_fetch_branches "$branch_list_arg")
77+
branch_selection_return_value="$?"
78+
7179
if [ "$#" -gt 1 ]
7280
then
7381
echo "Too many arguments."
@@ -99,7 +107,7 @@ git_delete_interactive() {
99107
echo "Selected branch: $selected_branch"
100108

101109
remote_branch_info="$(__gdi_get_info_remote_branch $selected_branch)"
102-
if [ -n "$remote_branch_info" ]
110+
if [ -n "$remote_branch_info" ] && [ $only_local_branch = false ]
103111
then
104112
remote_branch_name="$(echo $remote_branch_info | cut -d' ' -f1)"
105113
up_to_date_with_remote="$(echo $remote_branch_info | cut -d' ' -f2)"

0 commit comments

Comments
 (0)