Last active
April 11, 2024 13:14
-
-
Save messenger63/e69122304485939bbe30e9d5302b41e8 to your computer and use it in GitHub Desktop.
Script for release notes, that check if last commit was merge, then join all messages; otherwise takes just last commit message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if the last commit is a merge commit | |
# by getting commit parents (for merge there would be two parents) | |
if [[ $(git log --format=%P -n 1 | wc -w) -gt 1 ]]; then | |
LAST_COMMIT=$(git rev-parse HEAD) | |
MERGE_HASHES=$(git log --pretty=format:%H $LAST_COMMIT~...$LAST_COMMIT) | |
COMMIT_MESSAGE="" | |
# Loop through each merge commit and extract messages | |
for HASH in $MERGE_HASHES; do | |
# Skip the merge commit hash | |
if [[ "$HASH" == "$LAST_COMMIT" ]]; then | |
continue | |
fi | |
# Extract commit message for each parent commit | |
MESSAGE=$(git log --format=%B -n 1 $HASH) | |
# Append the commit message to the overall message | |
COMMIT_MESSAGE="$COMMIT_MESSAGE$MESSAGE\n" | |
done | |
# Output the combined commit messages | |
echo -e "$COMMIT_MESSAGE" | |
else | |
# If it's not a merge commit, get the message of the last commit | |
COMMIT_MESSAGE=$(git log --format=%B -n 1) | |
echo "$COMMIT_MESSAGE" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment