From 330461cf1e784be95e61a439c5b9e79ba9020104 Mon Sep 17 00:00:00 2001 From: Joe Schr <8218910+TheJoeSchr@users.noreply.github.com> Date: Thu, 2 Feb 2023 16:54:27 +0100 Subject: [PATCH] setup.sh: checks if git directory is dirty before bothering user with potentially scary question --- setup.sh | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/setup.sh b/setup.sh index b7dbe9684..da887a336 100755 --- a/setup.sh +++ b/setup.sh @@ -191,25 +191,37 @@ function update() { } # Reset Develop or Stable branch +function check_git_changes() { + if [ -z "$(git status --porcelain)" ]; then + echo "No changes in git directory" + return 0 + else + echo "Changes in git directory" + return 1 + fi +} function reset() { echo_block "Resetting branch and virtual env" if [ "1" == $(git branch -vv |grep -cE "\* develop|\* stable") ] then + if check_git_changes; then + read -p "Keep your local changes? (Otherwise will remove all changes you made!) [Y/n]? " + if [[ $REPLY =~ ^[Nn]$ ]]; then - read -p "Reset git branch? (This will remove all changes you made!) [y/N]? " - if [[ $REPLY =~ ^[Yy]$ ]]; then + git fetch -a - git fetch -a - - if [ "1" == $(git branch -vv | grep -c "* develop") ] - then - echo "- Hard resetting of 'develop' branch." - git reset --hard origin/develop - elif [ "1" == $(git branch -vv | grep -c "* stable") ] - then - echo "- Hard resetting of 'stable' branch." - git reset --hard origin/stable + if [ "1" == $(git branch -vv | grep -c "* develop") ] + then + echo "- Hard resetting of 'develop' branch." + git reset --hard origin/develop + elif [ "1" == $(git branch -vv | grep -c "* stable") ] + then + echo "- Hard resetting of 'stable' branch." + git reset --hard origin/stable + fi + else + echo "Reset ignored because you are not on 'stable' or 'develop'." fi fi else