Skip to content

Commit 928dc87

Browse files
authored
perf(download): git fetch之前询问, 方便调试 (#51)
* fix: redirect stdin from /dev/tty for interactive setup * feat: ask for confirmation before overwriting existing repo * feat: move update confirmation before git fetch
1 parent 814f4db commit 928dc87

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

download-and-install.sh

Lines changed: 17 additions & 5 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

@@ -59,10 +60,20 @@ if [ -d "$INSTALL_DIR" ]; then
5960
fi
6061
fi
6162

62-
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}"
63+
# Prompt for confirmation BEFORE any git operations
64+
echo -e "${YELLOW}Existing repository detected at $INSTALL_DIR.${NC}"
65+
echo -e "${YELLOW}Would you like to fetch and reset to latest origin/$BRANCH? (y/N)${NC}"
66+
read -p "> " confirm < /dev/tty
67+
68+
if [[ "$confirm" == "y" || "$confirm" == "Y" ]]; then
69+
echo -e "${BLUE}Updating repository...${NC}"
70+
git fetch origin
71+
git reset --hard "origin/$BRANCH"
72+
git clean -fd
73+
echo -e "${GREEN}Successfully updated and cleaned worktree.${NC}"
74+
else
75+
echo -e "${BLUE}Skipping update. Using existing local code.${NC}"
76+
fi
6677
else
6778
# Directory exists but is NOT a git repo (e.g. manual mkdir or unzip)
6879
if [ "$(ls -A $INSTALL_DIR)" ]; then
@@ -105,7 +116,8 @@ if [ -f "$DEPLOY_SCRIPT" ]; then
105116
echo ""
106117
# Switch to directory before execution to ensure relative paths work
107118
cd "$INSTALL_DIR"
108-
exec ./setup-services.sh
119+
# Ensure stdin is attached to terminal for interactive input
120+
exec ./setup-services.sh < /dev/tty
109121
else
110122
echo -e "${RED}Critical Error: setup-services.sh not found in downloaded repository!${NC}"
111123
exit 1

0 commit comments

Comments
 (0)