3 # Copyright (c) 2005 Linus Torvalds
9 die 'git commit [-a] [-s] [-v | --no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit>] [-e] [<path>...]'
12 all= logfile= use_commit= no_edit= log_given= log_message= verify=t signoff=
13 while case "$#" in 0) break;; esac
19 -F=*|--f=*|--fi=*|--fil=*|--file=*)
21 logfile=`expr "$1" : '-[^=]*=\(.*\)'`
24 -F|--f|--fi|--fil|--file)
25 case "$#" in 1) usage ;; esac; shift
30 -m=*|--m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*)
32 log_message=`expr "$1" : '-[^=]*=\(.*\)'`
35 -m|--m|--me|--mes|--mess|--messa|--messag|--message)
36 case "$#" in 1) usage ;; esac; shift
41 -c=*|--ree=*|--reed=*|--reedi=*|--reedit=*|--reedit-=*|--reedit-m=*|\
42 --reedit-me=*|--reedit-mes=*|--reedit-mess=*|--reedit-messa=*|\
43 --reedit-messag=*|--reedit-message=*)
45 use_commit=`expr "$1" : '-[^=]*=\(.*\)'`
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
53 -C=*|--reu=*|--reus=*|--reuse=*|--reuse-=*|--reuse-m=*|--reuse-me=*|\
54 --reuse-mes=*|--reuse-mess=*|--reuse-messa=*|--reuse-messag=*|\
57 use_commit=`expr "$1" : '-[^=]*=\(.*\)'`
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
67 -e|--e|--ed|--edi|--edit)
70 -s|--s|--si|--sig|--sign|--signo|--signof|--signoff)
73 -n|--n|--no|--no-|--no-v|--no-ve|--no-ver|--no-veri|--no-verif|--no-verify)
76 -v|--v|--ve|--ver|--veri|--verif|--verify)
91 die "Only one of -c/-C/-F/-m can be used." ;;
96 git-diff-files --name-only -z |
97 git-update-index --remove -z --stdin
100 die "Cannot use -a and explicit files at the same time."
105 git-diff-files --name-only -z -- "$@" |
106 git-update-index --remove -z --stdin
109 git-update-index -q --refresh || exit 1
113 if test -x "$GIT_DIR"/hooks/pre-commit
115 "$GIT_DIR"/hooks/pre-commit || exit
119 if test "$log_message" != ''
122 elif test "$logfile" != ""
124 if test "$logfile" = -
127 echo >&2 "(reading log message from standard input)"
132 elif test "$use_commit" != ""
134 git-cat-file commit "$use_commit" | sed -e '1,/^$/d'
135 elif test -f "$GIT_DIR/MERGE_HEAD" && test -f "$GIT_DIR/MERGE_MSG"
137 cat "$GIT_DIR/MERGE_MSG"
138 fi | git-stripspace >"$GIT_DIR"/COMMIT_EDITMSG
144 git-var GIT_COMMITTER_IDENT | sed -e '
148 } >>"$GIT_DIR"/COMMIT_EDITMSG
152 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
154 echo "# It looks like your may be committing a MERGE."
155 echo "# If this is not correct, please remove the file"
156 echo "# $GIT_DIR/MERGE_HEAD"
157 echo "# and try again"
159 fi >>"$GIT_DIR"/COMMIT_EDITMSG
162 if GIT_DIR="$GIT_DIR" git-rev-parse --verify HEAD >/dev/null 2>&1
164 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
165 PARENTS="-p HEAD "`sed -e 's/^/-p /' "$GIT_DIR/MERGE_HEAD"`
167 if test "$use_commit" != ""
172 s/^author \([^<]*\) <[^>]*> .*$/\1/
174 s/.*/GIT_AUTHOR_NAME='\''&'\''/p
177 s/^author [^<]* <\([^>]*\)> .*$/\1/
179 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
182 s/^author [^<]* <[^>]*> \(.*\)$/\1/
184 s/.*/GIT_AUTHOR_DATE='\''&'\''/p
189 set_author_env=`git-cat-file commit "$use_commit" |
190 LANG=C LC_ALL=C sed -ne "$pick_author_script"`
191 eval "$set_author_env"
192 export GIT_AUTHOR_NAME
193 export GIT_AUTHOR_EMAIL
194 export GIT_AUTHOR_DATE
197 if [ -z "$(git-ls-files)" ]; then
198 echo Nothing to commit 1>&2
203 git-status >>"$GIT_DIR"/COMMIT_EDITMSG
204 if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" ]
206 rm -f "$GIT_DIR/COMMIT_EDITMSG"
212 ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR/COMMIT_EDITMSG"
218 if test -x "$GIT_DIR"/hooks/commit-msg
220 "$GIT_DIR"/hooks/commit-msg "$GIT_DIR"/COMMIT_EDITMSG || exit
224 grep -v '^#' < "$GIT_DIR"/COMMIT_EDITMSG |
225 git-stripspace > "$GIT_DIR"/COMMIT_MSG
227 if cnt=`grep -v -i '^Signed-off-by' "$GIT_DIR"/COMMIT_MSG |
232 tree=$(git-write-tree) &&
233 commit=$(cat "$GIT_DIR"/COMMIT_MSG | git-commit-tree $tree $PARENTS) &&
234 git-update-ref HEAD $commit $current &&
235 rm -f -- "$GIT_DIR/MERGE_HEAD"
237 echo >&2 "* no commit message? aborting commit."
241 rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG"
243 if test -x "$GIT_DIR"/hooks/post-commit && test "$ret" = 0
245 "$GIT_DIR"/hooks/post-commit