From a895726cbd3b9201867a593a32bafb8b173b0b27 Mon Sep 17 00:00:00 2001 From: anonpenguin23 Date: Mon, 3 Nov 2025 07:21:44 +0200 Subject: [PATCH] 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. --- .githooks/pre-push | 3 ++- scripts/update_changelog.sh | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.githooks/pre-push b/.githooks/pre-push index db60b84..329b572 100644 --- a/.githooks/pre-push +++ b/.githooks/pre-push @@ -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}" diff --git a/scripts/update_changelog.sh b/scripts/update_changelog.sh index 11b889e..bc31dd1 100755 --- a/scripts/update_changelog.sh +++ b/scripts/update_changelog.sh @@ -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)"