gloriaJun / til

Lessoned Learned
3 stars 0 forks source link

git commit template #42

Open gloriaJun opened 5 years ago

gloriaJun commented 5 years ago

Show latest 5 commit message

#!/bin/sh

case "$2,$3" in
# merge,) ;;
#   /usr/bin/perl -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' "$1" ;;

 ,|template,)
    BRANCH_NAME=$(git branch | grep '*' | sed 's/* //')
    if [[ $BRANCH_NAME != '(no branch)' ]]
    then
      HASLOG=$(git log 2>&1)
      if [[ "$HASLOG" != *fatal* ]]; then
        echo "#" >> $1
        echo "# Last 5 commit messages" >> $1
        echo "# ----------------------" >> $1
        COMMITS=`git log --pretty=format:"# %h %s [%an]" -5`
        echo "${COMMITS}" >> $1
      fi
    fi
   ;;
#   /usr/bin/perl -i.bak -pe '
#      print "\n" . `git diff --cached --name-status -r`
#  if /^#/ && $first++ == 0' "$1" ;;

  *) ;;
esac