git-commit.shon commit git-daemon --base-path (b21c31c)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Linus Torvalds
   4#
   5
   6USAGE='[-a] [-s] [-v | --no-verify]  [-m <message> | -F <logfile> | (-C|-c) <commit>] [-e] [<path>...]'
   7. git-sh-setup
   8
   9all= logfile= use_commit= no_edit= log_given= log_message= verify=t signoff=
  10while case "$#" in 0) break;; esac
  11do
  12  case "$1" in
  13  -a|--a|--al|--all)
  14    all=t
  15    shift ;;
  16  -F=*|--f=*|--fi=*|--fil=*|--file=*)
  17    log_given=t$log_given
  18    logfile=`expr "$1" : '-[^=]*=\(.*\)'`
  19    no_edit=t
  20    shift ;;
  21  -F|--f|--fi|--fil|--file)
  22    case "$#" in 1) usage ;; esac; shift
  23    log_given=t$log_given
  24    logfile="$1"
  25    no_edit=t
  26    shift ;;
  27  -m=*|--m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*)
  28    log_given=t$log_given
  29    log_message=`expr "$1" : '-[^=]*=\(.*\)'`
  30    no_edit=t
  31    shift ;;
  32  -m|--m|--me|--mes|--mess|--messa|--messag|--message)
  33    case "$#" in 1) usage ;; esac; shift
  34    log_given=t$log_given
  35    log_message="$1"
  36    no_edit=t
  37    shift ;;
  38  -c=*|--ree=*|--reed=*|--reedi=*|--reedit=*|--reedit-=*|--reedit-m=*|\
  39  --reedit-me=*|--reedit-mes=*|--reedit-mess=*|--reedit-messa=*|\
  40  --reedit-messag=*|--reedit-message=*)
  41    log_given=t$log_given
  42    use_commit=`expr "$1" : '-[^=]*=\(.*\)'`
  43    shift ;;
  44  -c|--ree|--reed|--reedi|--reedit|--reedit-|--reedit-m|--reedit-me|\
  45  --reedit-mes|--reedit-mess|--reedit-messa|--reedit-messag|--reedit-message)
  46    case "$#" in 1) usage ;; esac; shift
  47    log_given=t$log_given
  48    use_commit="$1"
  49    shift ;;
  50  -C=*|--reu=*|--reus=*|--reuse=*|--reuse-=*|--reuse-m=*|--reuse-me=*|\
  51  --reuse-mes=*|--reuse-mess=*|--reuse-messa=*|--reuse-messag=*|\
  52  --reuse-message=*)
  53    log_given=t$log_given
  54    use_commit=`expr "$1" : '-[^=]*=\(.*\)'`
  55    no_edit=t
  56    shift ;;
  57  -C|--reu|--reus|--reuse|--reuse-|--reuse-m|--reuse-me|--reuse-mes|\
  58  --reuse-mess|--reuse-messa|--reuse-messag|--reuse-message)
  59    case "$#" in 1) usage ;; esac; shift
  60    log_given=t$log_given
  61    use_commit="$1"
  62    no_edit=t
  63    shift ;;
  64  -e|--e|--ed|--edi|--edit)
  65    no_edit=
  66    shift ;;
  67  -s|--s|--si|--sig|--sign|--signo|--signof|--signoff)
  68    signoff=t
  69    shift ;;
  70  -n|--n|--no|--no-|--no-v|--no-ve|--no-ver|--no-veri|--no-verif|--no-verify)
  71    verify=
  72    shift ;;
  73  -v|--v|--ve|--ver|--veri|--verif|--verify)
  74    verify=t
  75    shift ;;
  76  --)
  77    shift
  78    break ;;
  79  -*)
  80     usage ;;
  81  *)
  82    break ;;
  83  esac
  84done
  85
  86case "$log_given" in
  87tt*)
  88  die "Only one of -c/-C/-F/-m can be used." ;;
  89esac
  90
  91case "$all,$#" in
  92t,0)
  93        git-diff-files --name-only -z |
  94        git-update-index --remove -z --stdin
  95        ;;
  96t,*)
  97        die "Cannot use -a and explicit files at the same time."
  98        ;;
  99,0)
 100        ;;
 101*)
 102        git-diff-files --name-only -z -- "$@" |
 103        git-update-index --remove -z --stdin
 104        ;;
 105esac || exit 1
 106git-update-index -q --refresh || exit 1
 107
 108case "$verify" in
 109t)
 110        if test -x "$GIT_DIR"/hooks/pre-commit
 111        then
 112                "$GIT_DIR"/hooks/pre-commit || exit
 113        fi
 114esac
 115
 116if test "$log_message" != ''
 117then
 118        echo "$log_message"
 119elif test "$logfile" != ""
 120then
 121        if test "$logfile" = -
 122        then
 123                test -t 0 &&
 124                echo >&2 "(reading log message from standard input)"
 125                cat
 126        else
 127                cat <"$logfile"
 128        fi
 129elif test "$use_commit" != ""
 130then
 131        git-cat-file commit "$use_commit" | sed -e '1,/^$/d'
 132elif test -f "$GIT_DIR/MERGE_HEAD" && test -f "$GIT_DIR/MERGE_MSG"
 133then
 134        cat "$GIT_DIR/MERGE_MSG"
 135fi | git-stripspace >"$GIT_DIR"/COMMIT_EDITMSG
 136
 137case "$signoff" in
 138t)
 139        {
 140                echo
 141                git-var GIT_COMMITTER_IDENT | sed -e '
 142                        s/>.*/>/
 143                        s/^/Signed-off-by: /
 144                '
 145        } >>"$GIT_DIR"/COMMIT_EDITMSG
 146        ;;
 147esac
 148
 149if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
 150        echo "#"
 151        echo "# It looks like you may be committing a MERGE."
 152        echo "# If this is not correct, please remove the file"
 153        echo "# $GIT_DIR/MERGE_HEAD"
 154        echo "# and try again"
 155        echo "#"
 156fi >>"$GIT_DIR"/COMMIT_EDITMSG
 157
 158PARENTS="-p HEAD"
 159if GIT_DIR="$GIT_DIR" git-rev-parse --verify HEAD >/dev/null 2>&1
 160then
 161        if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
 162                PARENTS="-p HEAD "`sed -e 's/^/-p /' "$GIT_DIR/MERGE_HEAD"`
 163        fi
 164        if test "$use_commit" != ""
 165        then
 166                pick_author_script='
 167                /^author /{
 168                        s/'\''/'\''\\'\'\''/g
 169                        h
 170                        s/^author \([^<]*\) <[^>]*> .*$/\1/
 171                        s/'\''/'\''\'\'\''/g
 172                        s/.*/GIT_AUTHOR_NAME='\''&'\''/p
 173
 174                        g
 175                        s/^author [^<]* <\([^>]*\)> .*$/\1/
 176                        s/'\''/'\''\'\'\''/g
 177                        s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
 178
 179                        g
 180                        s/^author [^<]* <[^>]*> \(.*\)$/\1/
 181                        s/'\''/'\''\'\'\''/g
 182                        s/.*/GIT_AUTHOR_DATE='\''&'\''/p
 183
 184                        q
 185                }
 186                '
 187                set_author_env=`git-cat-file commit "$use_commit" |
 188                LANG=C LC_ALL=C sed -ne "$pick_author_script"`
 189                eval "$set_author_env"
 190                export GIT_AUTHOR_NAME
 191                export GIT_AUTHOR_EMAIL
 192                export GIT_AUTHOR_DATE
 193        fi
 194else
 195        if [ -z "$(git-ls-files)" ]; then
 196                echo Nothing to commit 1>&2
 197                exit 1
 198        fi
 199        PARENTS=""
 200fi
 201git-status >>"$GIT_DIR"/COMMIT_EDITMSG
 202if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" ]
 203then
 204        rm -f "$GIT_DIR/COMMIT_EDITMSG"
 205        git-status
 206        exit 1
 207fi
 208case "$no_edit" in
 209'')
 210        ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR/COMMIT_EDITMSG"
 211        ;;
 212esac
 213
 214case "$verify" in
 215t)
 216        if test -x "$GIT_DIR"/hooks/commit-msg
 217        then
 218                "$GIT_DIR"/hooks/commit-msg "$GIT_DIR"/COMMIT_EDITMSG || exit
 219        fi
 220esac
 221
 222grep -v '^#' < "$GIT_DIR"/COMMIT_EDITMSG |
 223git-stripspace > "$GIT_DIR"/COMMIT_MSG
 224
 225if cnt=`grep -v -i '^Signed-off-by' "$GIT_DIR"/COMMIT_MSG |
 226        git-stripspace |
 227        wc -l` &&
 228   test 0 -lt $cnt
 229then
 230        tree=$(git-write-tree) &&
 231        commit=$(cat "$GIT_DIR"/COMMIT_MSG | git-commit-tree $tree $PARENTS) &&
 232        git-update-ref HEAD $commit $current &&
 233        rm -f -- "$GIT_DIR/MERGE_HEAD"
 234else
 235        echo >&2 "* no commit message?  aborting commit."
 236        false
 237fi
 238ret="$?"
 239rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG"
 240
 241if test -x "$GIT_DIR"/hooks/post-commit && test "$ret" = 0
 242then
 243        "$GIT_DIR"/hooks/post-commit
 244fi
 245exit "$ret"