Skip to content

Commit e8fdf9a

Browse files
committed
feat(gitguard): add interactive mode enforcement during remote installation
1 parent 3653ced commit e8fdf9a

File tree

1 file changed

+34
-19
lines changed

1 file changed

+34
-19
lines changed

packages/gitguard/install.sh

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ main() {
152152

153153
# Determine installation options
154154
if [ "$project_status" = "none" ] && [ "$global_status" = "none" ]; then
155+
# Both are not installed - ask where to install
155156
echo -e "\nWhere would you like to install GitGuard?"
156157
echo -e "1) Project only ${GREEN}[default]${NC}"
157158
echo -e "2) Global only"
@@ -175,26 +176,37 @@ main() {
175176
;;
176177
esac
177178
else
178-
# Handle existing installations
179-
if [ "$project_status" = "gitguard" ] || [ "$global_status" = "gitguard" ]; then
180-
echo -e "\n${YELLOW}GitGuard is already installed. What would you like to do?${NC}"
181-
echo -e "1) Reinstall existing hooks ${GREEN}[default]${NC}"
182-
echo -e "2) Cancel"
183-
read -p "Select an option (1-2, press Enter to reinstall): " -r < /dev/tty
184-
echo
185-
186-
# Default to option 1 (reinstall) if Enter is pressed
187-
REPLY=${REPLY:-1}
188-
189-
case $REPLY in
190-
2) echo -e "${YELLOW}Installation cancelled.${NC}" ;;
191-
*)
192-
# Directly reinstall without additional confirmation
193-
[ "$project_status" = "gitguard" ] && handle_installation "$(git rev-parse --git-dir)/hooks" "project"
194-
[ "$global_status" = "gitguard" ] && handle_installation "$GLOBAL_GIT_DIR" "global"
195-
;;
196-
esac
179+
# At least one is installed - show reinstall/install options
180+
echo -e "\n${YELLOW}Installation options:${NC}"
181+
if [ "$project_status" = "none" ]; then
182+
echo -e "1) Install project hooks"
183+
else
184+
echo -e "1) Reinstall project hooks"
185+
fi
186+
if [ "$global_status" = "none" ]; then
187+
echo -e "2) Install global hooks"
188+
else
189+
echo -e "2) Reinstall global hooks"
197190
fi
191+
echo -e "3) Cancel ${GREEN}[default]${NC}"
192+
193+
read -p "Select an option (1-3, press Enter to cancel): " -r < /dev/tty
194+
echo
195+
196+
case $REPLY in
197+
1)
198+
if [ -n "$(git rev-parse --git-dir 2>/dev/null)" ]; then
199+
handle_installation "$(git rev-parse --git-dir)/hooks" "project"
200+
else
201+
echo -e "${RED}Not in a git repository${NC}"
202+
fi
203+
;;
204+
2) handle_installation "$GLOBAL_GIT_DIR" "global" ;;
205+
*)
206+
echo -e "${YELLOW}Installation cancelled.${NC}"
207+
exit 0
208+
;;
209+
esac
198210
fi
199211
}
200212

@@ -216,6 +228,9 @@ handle_remote_install() {
216228
# Set script directory to temp directory for installation
217229
SCRIPT_DIR="$temp_dir"
218230

231+
# Force interactive mode
232+
export INTERACTIVE=1
233+
219234
# Run the main installation
220235
main
221236
}

0 commit comments

Comments
 (0)