Make rmbranch more robust
This commit is contained in:
parent
8e04a5db62
commit
a7bfe90bf5
1 changed files with 23 additions and 9 deletions
32
bin/g
32
bin/g
|
|
@ -183,32 +183,46 @@ fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
rmbranch)
|
rmbranch)
|
||||||
echo 'Delete branch'
|
|
||||||
if [ -z "$2" ]; then
|
if [ -z "$2" ]; then
|
||||||
echo '! Specify branch name'
|
echo '! Specify branch name'
|
||||||
exit;
|
exit;
|
||||||
fi
|
fi
|
||||||
|
echo "Delete branch $2"
|
||||||
if ! git rev-parse --quiet --verify "$2" >/dev/null
|
if ! git rev-parse --quiet --verify "$2" >/dev/null
|
||||||
then
|
then
|
||||||
echo "Branch not found: '$2'"
|
echo "Branch not found: '$2'"
|
||||||
exit;
|
exit;
|
||||||
fi
|
fi
|
||||||
# else
|
# 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 [[ "$?" -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 ''
|
echo ''
|
||||||
git branch -D "$2"
|
git branch -D "$2"
|
||||||
else
|
else
|
||||||
echo ''
|
echo ''
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if confirm 'Would you like to delete this branch on the remote as well?'; then
|
|
||||||
echo ''
|
ls $(git_root)/.git/refs/remotes/*/$2 &>/dev/null
|
||||||
git push origin --delete "$2"
|
if [[ "$?" -eq 0 ]]; then
|
||||||
else
|
if confirm 'Would you like to delete this branch on the remote as well?'; then
|
||||||
echo ''
|
echo ''
|
||||||
echo 'OK, just thought I'"'"'d ask.'
|
git push origin --delete "$2"
|
||||||
|
else
|
||||||
|
echo ''
|
||||||
|
echo 'OK, just thought I'"'"'d ask.'
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue