Skip to content

Commit 2b2c1dd

Browse files
committed
feat: ask for confirmation before overwriting existing repo
1 parent 3c02815 commit 2b2c1dd

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

download-and-install.sh

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ set -e
1313
# Colors
1414
GREEN='\033[0;32m'
1515
BLUE='\033[0;34m'
16+
YELLOW='\033[1;33m'
1617
RED='\033[0;31m'
1718
NC='\033[0m'
1819

@@ -60,9 +61,24 @@ if [ -d "$INSTALL_DIR" ]; then
6061
fi
6162

6263
git fetch origin
63-
git reset --hard "origin/$BRANCH"
64-
git clean -fd
65-
echo -e "${GREEN}Successfully reset to origin/$BRANCH and cleaned worktree.${NC}"
64+
65+
# Prompt for confirmation before overwriting
66+
echo -e "${YELLOW}Warning: The directory $INSTALL_DIR already contains a repository.${NC}"
67+
echo -e "${YELLOW}Updating will perform a hard reset and discard all local changes.${NC}"
68+
# Read from /dev/tty to handle pipe execution
69+
if [ -t 0 ]; then
70+
read -p "Do you want to update and reset the repository? (y/N) " confirm
71+
else
72+
read -p "Do you want to update and reset the repository? (y/N) " confirm < /dev/tty
73+
fi
74+
75+
if [[ "$confirm" == "y" || "$confirm" == "Y" ]]; then
76+
git reset --hard "origin/$BRANCH"
77+
git clean -fd
78+
echo -e "${GREEN}Successfully reset to origin/$BRANCH and cleaned worktree.${NC}"
79+
else
80+
echo -e "${YELLOW}Skipping repository update. Using existing local code.${NC}"
81+
fi
6682
else
6783
# Directory exists but is NOT a git repo (e.g. manual mkdir or unzip)
6884
if [ "$(ls -A $INSTALL_DIR)" ]; then

0 commit comments

Comments
 (0)