Skip to content

Commit cf64804

Browse files
committed
Stop if trying to delete current branch
1 parent 6fef09e commit cf64804

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

git-delete-branch-interactive.sh

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,19 @@ git_delete_interactive() {
123123
fi
124124
fi
125125

126-
echo -n "Delete local branch $selected_branch (the last copy of the work)? [y/N] "
127-
read delete_local_branch
128-
echo "answer: $delete_local_branch"
129-
if [[ "$delete_local_branch" =~ [yY] ]]
126+
if [ "$selected_branch" = "$(git_current_branch)" ]
130127
then
131-
echo "Deleting local branch $selected_branch"
132-
git branch -D $selected_branch
128+
echo "Cannot delete current local branch. Please checkout another branch and retry."
129+
return 1
130+
else
131+
echo -n "Delete local branch $selected_branch (the last copy of the work)? [y/N] "
132+
read delete_local_branch
133+
echo "answer: $delete_local_branch"
134+
if [[ "$delete_local_branch" =~ [yY] ]]
135+
then
136+
echo "Deleting local branch $selected_branch"
137+
git branch -D $selected_branch
138+
fi
133139
fi
134140
fi
135141
fi

0 commit comments

Comments
 (0)