Make rmbranch more robust

This commit is contained in:
Will Hilton 2017-03-14 22:33:30 -04:00
parent 8e04a5db62
commit a7bfe90bf5
No known key found for this signature in database
GPG key ID: 9609B8A5928BA6B9

20
bin/g
View file

@ -183,26 +183,39 @@ fi
;;
rmbranch)
echo 'Delete branch'
if [ -z "$2" ]; then
echo '! Specify branch name'
exit;
fi
echo "Delete branch $2"
if ! git rev-parse --quiet --verify "$2" >/dev/null
then
echo "Branch not found: '$2'"
exit;
fi
# else
git branch -d "$2" >/dev/null
current_branch=$(git rev-parse --abbrev-ref HEAD)
if [[ "$current_branch" == "$2" ]]; then
if confirm "You are currently on the branch '$2'! Do you want me to switch to 'master'?"; then
echo ''
git checkout master
else
echo ''
fi
fi
git branch -d "$2" &>/dev/null
if [[ "$?" -ne 0 ]]; then
if confirm 'This branch hasn'"'"'t been merged. Are sure you want to delete this branch?'; then
if confirm "The branch '$2' hasn't been merged. Are sure you want to delete this branch?"; then
echo ''
git branch -D "$2"
else
echo ''
fi
fi
ls $(git_root)/.git/refs/remotes/*/$2 &>/dev/null
if [[ "$?" -eq 0 ]]; then
if confirm 'Would you like to delete this branch on the remote as well?'; then
echo ''
git push origin --delete "$2"
@ -210,6 +223,7 @@ else
echo ''
echo 'OK, just thought I'"'"'d ask.'
fi
fi
;;
mvbranch)