diff --git a/Readme.md b/Readme.md index e2c96e1..a82e584 100644 --- a/Readme.md +++ b/Readme.md @@ -458,9 +458,9 @@ since the previous tag. (If there are no tags, populates commits since the proj Opens the changelog in `$EDITOR` when set. ```bash -$ git changelog && cat History.md +$ git changelog --tag 1.5.2 && cat History.md -n.n.n / 2010-08-05 +1.5.2 / 2010-08-05 ================== * Docs for git-ignore. Closes #3 diff --git a/bin/git-changelog b/bin/git-changelog index af602ce..6bf1455 100755 --- a/bin/git-changelog +++ b/bin/git-changelog @@ -1,29 +1,49 @@ #!/bin/sh -DATE=`date +'%Y-%m-%d'` -HEAD="\nn.n.n / $DATE \n==================\n\n" +FILE="" +LIST=false +TAG="n.n.n" -case "$1" in - -l|--list) - version=$(git describe --tags --abbrev=0 $(git rev-list --tags --max-count=1)) - if test -z "$version"; then - git log --pretty="format: * %s" - else - git log --pretty="format: * %s" $version.. - fi - ;; - *) - CHANGELOG=$1 - if test "$CHANGELOG" = ""; then - CHANGELOG=`ls | egrep 'change|history' -i` - if test "$CHANGELOG" = ""; then CHANGELOG='History.md'; fi - fi - tmp="/tmp/changelog" - printf "$HEAD" > $tmp - git-changelog --list >> $tmp - printf '\n' >> $tmp - if [ -f $CHANGELOG ]; then cat $CHANGELOG >> $tmp; fi - mv $tmp $CHANGELOG - test -n "$EDITOR" && $EDITOR $CHANGELOG - ;; -esac +while [ "$1" != "" ]; do + case $1 in + -l | --list ) + LIST=true + ;; + -t | --tag ) + TAG=$2 + shift + ;; + * ) + FILE=$1 + ;; + esac + shift +done + +DATE=`date +'%Y-%m-%d'` +HEAD="\n$TAG / $DATE \n==================\n\n" + +if $LIST; then + version=$(git describe --tags --abbrev=0 $(git rev-list --tags --max-count=1)) + if test -z "$version"; then + git log --pretty="format: * %s" + else + git log --pretty="format: * %s" $version.. + fi + exit +fi + +CHANGELOG=$FILE +if test "$CHANGELOG" = ""; then + CHANGELOG=`ls | egrep 'change|history' -i` + if test "$CHANGELOG" = ""; then + CHANGELOG='History.md'; + fi +fi +tmp="/tmp/changelog" +printf "$HEAD" > $tmp +git-changelog --list >> $tmp +printf '\n' >> $tmp +if [ -f $CHANGELOG ]; then cat $CHANGELOG >> $tmp; fi +mv $tmp $CHANGELOG +test -n "$EDITOR" && $EDITOR $CHANGELOG diff --git a/etc/bash_completion.sh b/etc/bash_completion.sh index db68dfa..e6dbca7 100644 --- a/etc/bash_completion.sh +++ b/etc/bash_completion.sh @@ -5,7 +5,7 @@ _git_bug(){ } _git_changelog(){ - __gitcomp "--list" + __gitcomp "-l -t --list --tag" } _git_contrib(){