feat: ask to remove branch in git-merge-patch

When trying to merge-patch it will fail if the branch you are trying to merge is
already on the local machine.

This will ask if you want to remove it. The branch will be removed locally and
then pulled from the remote to ensure you are not merging any un-pushed local
changes.
This commit is contained in:
Ade Attwood 2022-03-13 20:33:15 +00:00
parent 2965923990
commit 7c184d8616

View file

@ -62,6 +62,20 @@ if [[ "$MERGE_BRANCH" != "--continue" ]]; then
#
git fetch
#
# Ask the user if they would like to remove the local branch if it exists locally
#
if [[ ! -z "$(git branch --list $MERGE_BRANCH)" ]]; then
while true; do
read -p "Branch '$MERGE_BRANCH' exists locally would you like to remove it? " yn
case $yn in
[Yy]* ) git branch -D "$MERGE_BRANCH"; break;;
[Nn]* ) echo "Exiting you need to remove branch '$MERGE_BRANCH' manually before merge-patching"; exit;;
* ) echo "Please answer yes or no.";;
esac
done
fi
#
# Check out the merge branch from the origin
#