git-commit-scripton commit git-commit: log parameter updates. (0c09129)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Linus Torvalds
   4#
   5
   6. git-sh-setup-script || die "Not a git archive"
   7
   8usage () {
   9        die 'git commit [-a]  [-m <message>] [-F <logfile>] [(-C|-c) <commit>] [<path>...]'
  10}
  11
  12all= logfile= use_commit= no_edit= log_given= log_message=
  13while case "$#" in 0) break;; esac
  14do
  15  case "$1" in
  16  -a|--a|--al|--all)
  17    all=t
  18    shift ;;
  19  -F=*|--f=*|--fi=*|--fil=*|--file=*)
  20    log_given=t$log_given
  21    logfile=`expr "$1" : '-[^=]*=\(.*\)'`
  22    no_edit=t
  23    shift ;;
  24  -F|--f|--fi|--fil|--file)
  25    case "$#" in 1) usage ;; esac; shift
  26    log_given=t$log_given
  27    logfile="$1"
  28    no_edit=t
  29    shift ;;
  30  -m=*|--m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*)
  31    log_given=t$log_given
  32    log_message=`expr "$1" : '-[^=]*=\(.*\)'`
  33    no_edit=t
  34    shift ;;
  35  -m|--m|--me|--mes|--mess|--messa|--messag|--message)
  36    case "$#" in 1) usage ;; esac; shift
  37    log_given=t$log_given
  38    log_message="$1"
  39    no_edit=t
  40    shift ;;
  41  -c=*|--ree=*|--reed=*|--reedi=*|--reedit=*|--reedit-=*|--reedit-m=*|\
  42  --reedit-me=*|--reedit-mes=*|--reedit-mess=*|--reedit-messa=*|\
  43  --reedit-messag=*|--reedit-message=*)
  44    log_given=t$log_given
  45    use_commit=`expr "$1" : '-[^=]*=\(.*\)'`
  46    shift ;;
  47  -c|--ree|--reed|--reedi|--reedit|--reedit-|--reedit-m|--reedit-me|\
  48  --reedit-mes|--reedit-mess|--reedit-messa|--reedit-messag|--reedit-message)
  49    case "$#" in 1) usage ;; esac; shift
  50    log_given=t$log_given
  51    use_commit="$1"
  52    shift ;;
  53  -C=*|--reu=*|--reus=*|--reuse=*|--reuse-=*|--reuse-m=*|--reuse-me=*|\
  54  --reuse-mes=*|--reuse-mess=*|--reuse-messa=*|--reuse-messag=*|\
  55  --reuse-message=*)
  56    log_given=t$log_given
  57    use_commit=`expr "$1" : '-[^=]*=\(.*\)'`
  58    no_edit=t
  59    shift ;;
  60  -C|--reu|--reus|--reuse|--reuse-|--reuse-m|--reuse-me|--reuse-mes|\
  61  --reuse-mess|--reuse-messa|--reuse-messag|--reuse-message)
  62    case "$#" in 1) usage ;; esac; shift
  63    log_given=t$log_given
  64    use_commit="$1"
  65    no_edit=t
  66    shift ;;
  67  --)
  68    shift
  69    break ;;
  70  -*)
  71     usage ;;
  72  *)
  73    break ;;
  74  esac
  75done
  76
  77case "$log_given" in
  78tt*)
  79  die "Only one of -c/-C/-F/-m can be used." ;;
  80esac
  81
  82case "$all" in
  83t)
  84        git-diff-files --name-only -z |
  85        xargs -0 git-update-cache -q -- || exit 1 ;;
  86esac
  87git-update-cache -q --refresh -- "$@" || exit 1
  88
  89PARENTS="-p HEAD"
  90if [ ! -r "$GIT_DIR/HEAD" ]; then
  91        if [ -z "$(git-ls-files)" ]; then
  92                echo Nothing to commit 1>&2
  93                exit 1
  94        fi
  95        {
  96                echo "#"
  97                echo "# Initial commit"
  98                case "$no_edit" in
  99                t) echo "# (ignoring your commit message for initial commit)"
 100                   no_edit= 
 101                esac
 102                echo "#"
 103                git-ls-files | sed 's/^/# New file: /'
 104                echo "#"
 105        } >.editmsg
 106        PARENTS=""
 107        no_edit=
 108else
 109        if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
 110                echo "#"
 111                echo "# It looks like your may be committing a MERGE."
 112                echo "# If this is not correct, please remove the file"
 113                echo "# $GIT_DIR/MERGE_HEAD"
 114                echo "# and try again"
 115                case "$no_edit" in
 116                t) echo "# (ignoring your commit message for merge commit)"
 117                   no_edit= 
 118                esac
 119                echo "#"
 120                PARENTS="-p HEAD -p MERGE_HEAD"
 121        elif test "$log_message" != ''
 122        then
 123                echo "$log_message"
 124        elif test "$logfile" != ""
 125        then
 126                if test "$logfile" = -
 127                then
 128                        test -t 0 &&
 129                        echo >&2 "(reading log message from standard input)"
 130                        cat
 131                else
 132                        cat <"$logfile"
 133                fi
 134        elif test "$use_commit" != ""
 135        then
 136                pick_author_script='
 137                /^author /{
 138                        h
 139                        s/^author \([^<]*\) <[^>]*> .*$/\1/
 140                        s/'\''/'\''\'\'\''/g
 141                        s/.*/GIT_AUTHOR_NAME='\''&'\''/p
 142
 143                        g
 144                        s/^author [^<]* <\([^>]*\)> .*$/\1/
 145                        s/'\''/'\''\'\'\''/g
 146                        s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
 147
 148                        g
 149                        s/^author [^<]* <[^>]*> \(.*\)$/\1/
 150                        s/'\''/'\''\'\'\''/g
 151                        s/.*/GIT_AUTHOR_DATE='\''&'\''/p
 152
 153                        q
 154                }
 155                '
 156                set_author_env=`git-cat-file commit "$use_commit" |
 157                sed -ne "$pick_author_script"`
 158                eval "$set_author_env"
 159                export GIT_AUTHOR_NAME
 160                export GIT_AUTHOR_EMAIL
 161                export GIT_AUTHOR_DATE
 162                git-cat-file commit "$use_commit" |
 163                sed -e '1,/^$/d'
 164        fi >.editmsg
 165        git-status-script >>.editmsg
 166fi
 167if [ "$?" != "0" -a ! -f $GIT_DIR/MERGE_HEAD ]
 168then
 169        cat .editmsg
 170        rm .editmsg
 171        exit 1
 172fi
 173case "$no_edit" in
 174'')
 175        ${VISUAL:-${EDITOR:-vi}} .editmsg
 176        ;;
 177esac
 178grep -v '^#' < .editmsg | git-stripspace > .cmitmsg
 179if test -s .cmitmsg
 180then
 181        tree=$(git-write-tree) &&
 182        commit=$(cat .cmitmsg | git-commit-tree $tree $PARENTS) &&
 183        echo $commit > "$GIT_DIR/HEAD" &&
 184        rm -f -- "$GIT_DIR/MERGE_HEAD"
 185else
 186        echo >&2 "* no commit message?  aborting commit."
 187        false
 188fi
 189ret="$?"
 190rm -f .cmitmsg .editmsg
 191exit "$ret"