From 2b51859ea7c5553855ee0d3d6c28fe262824a539 Mon Sep 17 00:00:00 2001 From: anonpenguin23 Date: Mon, 3 Nov 2025 07:32:42 +0200 Subject: [PATCH] fix: enhance changelog update logic to prevent infinite loops - Added checks to skip changelog updates if the only unpushed commit is a changelog update commit. - Improved handling of multiple unpushed commits by excluding the latest changelog commit from the diff analysis. - Cleaned up temporary changelog preview files when no other changes are detected. --- scripts/update_changelog.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/scripts/update_changelog.sh b/scripts/update_changelog.sh index fb05d1c..334b2c6 100755 --- a/scripts/update_changelog.sh +++ b/scripts/update_changelog.sh @@ -108,6 +108,28 @@ 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" +# Check if the only unpushed commit is a changelog update commit +# If so, exclude it from the diff to avoid infinite loops +if [ "$UNPUSHED_COMMITS" -gt 0 ]; then + LATEST_COMMIT_MSG=$(git log -1 --pretty=%B HEAD 2>/dev/null || echo "") + if echo "$LATEST_COMMIT_MSG" | grep -q "chore: update changelog and version"; then + # If the latest commit is a changelog commit, check if there are other commits + if [ "$UNPUSHED_COMMITS" -eq 1 ]; then + log "Latest commit is a changelog update. No other changes detected. Skipping changelog update." + # Clean up any old preview files + rm -f "$REPO_ROOT/.changelog_preview.tmp" "$REPO_ROOT/.changelog_version.tmp" + exit 0 + else + # Multiple commits, exclude the latest changelog commit from diff + log "Multiple unpushed commits detected. Excluding latest changelog commit from analysis." + # Get all commits except the latest one + UNPUSHED_DIFF=$(git diff "$REMOTE_BRANCH"..HEAD~1 2>/dev/null || echo "") + UNPUSHED_COMMITS=$(git rev-list --count "$REMOTE_BRANCH"..HEAD~1 2>/dev/null || echo "0") + [ -z "$UNPUSHED_COMMITS" ] && UNPUSHED_COMMITS="0" + fi + fi +fi + log "Found: $UNSTAGED_COUNT unstaged file(s), $STAGED_COUNT staged file(s), $UNPUSHED_COMMITS unpushed commit(s)" # Combine all diffs