Created
January 31, 2014 10:20
-
-
Save maxpeterson/8729637 to your computer and use it in GitHub Desktop.
Bash function to build a changelog based on the tags and commit entries of a git repo
This file contains hidden or 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
| changelog_entry() { | |
| # Output individual changelog entry | |
| usage="changelog_entry <since> <until>" | |
| since=${1} | |
| until=${2} | |
| if [ "${since}" == "" ] ; then | |
| echo "No 'since' version" | |
| echo ${usage} | |
| return 1 | |
| fi | |
| if [ "${until}" == "" ] ; then | |
| echo "No 'until' version" | |
| echo ${usage} | |
| return 1 | |
| fi | |
| echo | |
| echo "## $until" | |
| echo | |
| git log "${since}...${until}" --pretty=format:"* %s" --reverse | grep -v Merge; | |
| } | |
| changelog() { | |
| # Output all commit entries for a git repo as a changelog | |
| until='' | |
| while read major; do | |
| # OSX `sort` does not support `--version-order` so first loop the | |
| # major part of the version number | |
| while read since; do | |
| if [ "$until" != "" ]; then | |
| changelog_entry $since $until | |
| fi | |
| until=$since | |
| done < <(git tag | grep "^$major" | sort -r -t . -k 2 -n) | |
| done < <(git tag | sed -e 's/^\(v[^.]*\)\..*/\1/' | sort -u -r) | |
| # Find the first commit to output entries between the first commit and the | |
| # first tag. | |
| first=$(git rev-list --max-parents=0 HEAD) | |
| changelog_entry $first $until | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment