tj.git-extras/bin/git-changelog
Sasha Khamkov bd80a4e512 FIX: check if un-pushed commits
- switch the check for un-pushed commits from `diff-index` to more simple check
- still ignores sub-modules

Closes #234

Clarification: 
As pointed by @cristiandouce in #234 - my flow was different (and pretty stupid to be honest on some particular project of mine) so some other work flow scenarios was failing to pass. 

I still feel such check is needed, because it is still populates Changelog|History files with empty lines if no un-pushed commits exist, so @hemanth merge this one or revert the [619232e](619232ef86)
2014-07-11 23:43:12 +03:00

62 lines
1.2 KiB
Bash
Executable file

#!/bin/sh
FILE=""
LIST=false
TAG="n.n.n"
GIT_LOG_OPTS=""
if [[ -z $(git log --ignore-submodules origin..HEAD) ]]; then
echo 'No unpushed commits.';
exit 1;
fi
while [ "$1" != "" ]; do
case $1 in
-l | --list )
LIST=true
;;
-t | --tag )
TAG=$2
shift
;;
--no-merges )
GIT_LOG_OPTS='--no-merges'
;;
* )
FILE=$1
;;
esac
shift
done
DATE=`date +'%Y-%m-%d'`
HEAD="\n$TAG / $DATE\n"
for i in $(seq 5 ${#HEAD}); do HEAD="$HEAD="; done
HEAD="$HEAD\n\n"
if $LIST; then
lasttag=$(git rev-list --tags --max-count=1 2>/dev/null)
version=$(git describe --tags --abbrev=0 $lasttag 2>/dev/null)
if test -z "$version"; then
git log $GIT_LOG_OPTS --pretty="format: * %s"
else
git log $GIT_LOG_OPTS --pretty="format: * %s" $version..
fi
exit
fi
CHANGELOG=$FILE
if test "$CHANGELOG" = ""; then
CHANGELOG=`ls | egrep 'change|history' -i|head -n1`
if test "$CHANGELOG" = ""; then
CHANGELOG='History.md';
fi
fi
tmp="/tmp/changelog"
printf "$HEAD" > $tmp
git-changelog $GIT_LOG_OPTS --list >> $tmp
printf '\n' >> $tmp
if [ -f $CHANGELOG ]; then cat $CHANGELOG >> $tmp; fi
mv $tmp $CHANGELOG
test -n "$EDITOR" && $EDITOR $CHANGELOG