fix: improve user confirmation handling in pre-push hook

- Updated the pre-push hook to read user confirmation directly from /dev/tty, ensuring it works correctly in all terminal contexts.
- This change enhances the reliability of the push confirmation process, preventing potential issues with user input in non-interactive environments.
This commit is contained in:
anonpenguin23 2025-11-03 07:21:44 +02:00
parent f1fcbf69cf
commit a895726cbd
2 changed files with 5 additions and 1 deletions

View File

@ -44,7 +44,8 @@ if [ -f "$CHANGELOG_SCRIPT" ]; then
echo -e "${BLUE}────────────────────────────────────────────────────────────────────────${NOCOLOR}"
echo ""
echo -e "${YELLOW}Do you want to proceed with the push? (yes/no):${NOCOLOR} "
read -r confirmation
# Read from /dev/tty to ensure we can read from terminal even in git hook context
read -r confirmation < /dev/tty
if [ "$confirmation" != "yes" ]; then
echo -e "${RED}Push aborted by user.${NOCOLOR}"

View File

@ -96,14 +96,17 @@ log "Collecting git diffs..."
# Unstaged changes
UNSTAGED_DIFF=$(git diff 2>/dev/null || echo "")
UNSTAGED_COUNT=$(echo "$UNSTAGED_DIFF" | grep -c "^diff\|^index" 2>/dev/null || echo "0")
[ -z "$UNSTAGED_COUNT" ] && UNSTAGED_COUNT="0"
# Staged changes
STAGED_DIFF=$(git diff --cached 2>/dev/null || echo "")
STAGED_COUNT=$(echo "$STAGED_DIFF" | grep -c "^diff\|^index" 2>/dev/null || echo "0")
[ -z "$STAGED_COUNT" ] && STAGED_COUNT="0"
# Unpushed commits
UNPUSHED_DIFF=$(git diff "$REMOTE_BRANCH"..HEAD 2>/dev/null || echo "")
UNPUSHED_COMMITS=$(git rev-list --count "$REMOTE_BRANCH"..HEAD 2>/dev/null || echo "0")
[ -z "$UNPUSHED_COMMITS" ] && UNPUSHED_COMMITS="0"
log "Found: $UNSTAGED_COUNT unstaged file(s), $STAGED_COUNT staged file(s), $UNPUSHED_COMMITS unpushed commit(s)"