Skip to content

Commit 74fd269

Browse files
committed
feat: update pre-commit hook to regenerate full changelog for new commits
1 parent e994950 commit 74fd269

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

.githooks/pre-commit

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,27 @@ echo "Updating changelog with new entries..."
2222

2323
# Check if CHANGELOG.md exists
2424
if [ -f "CHANGELOG.md" ]; then
25-
# Changelog exists, only add new unreleased entries
26-
echo "Existing changelog found. Adding new unreleased entries..."
27-
# Generate unreleased entries and prepend to existing changelog
28-
git-cliff --unreleased --output /tmp/new_entries.md
29-
if [ -s /tmp/new_entries.md ]; then
30-
# If there are new entries, prepend them to existing changelog
31-
cat /tmp/new_entries.md CHANGELOG.md > /tmp/updated_changelog.md
32-
mv /tmp/updated_changelog.md CHANGELOG.md
33-
rm -f /tmp/new_entries.md
25+
# Changelog exists, check if there are unreleased commits to add
26+
echo "Existing changelog found. Checking for new unreleased entries..."
27+
28+
# Check if there are any unreleased commits
29+
if git log --oneline $(git describe --tags --abbrev=0 2>/dev/null || echo "HEAD~999")..HEAD --quiet 2>/dev/null; then
30+
echo "New commits found. Regenerating full changelog..."
31+
# Backup existing changelog
32+
cp CHANGELOG.md CHANGELOG.md.backup
33+
34+
# Generate complete changelog (this handles unreleased + existing properly)
35+
git-cliff --output CHANGELOG.md
36+
37+
# If generation fails, restore backup
38+
if [ $? -ne 0 ]; then
39+
mv CHANGELOG.md.backup CHANGELOG.md
40+
echo "Failed to generate changelog, restored backup"
41+
else
42+
rm -f CHANGELOG.md.backup
43+
fi
44+
else
45+
echo "No new commits to add to changelog."
3446
fi
3547
else
3648
# No changelog exists, create it from scratch

0 commit comments

Comments
 (0)