blob: 476f4f18dbb76041fbbfe6243785ad4997a7e7c7 [file] [log] [blame]
Linus Torvaldsa3e870f2005-05-30 12:51:00 -07001#!/bin/sh
Junio C Hamano5fec3ef2005-06-25 02:22:05 -07002#
3# Copyright (c) 2005 Linus Torvalds
Junio C Hamano130fcca2006-02-05 00:07:44 -08004# Copyright (c) 2006 Junio C Hamano
Junio C Hamano5fec3ef2005-06-25 02:22:05 -07005
Peter Eriksen497171e2007-01-24 20:54:46 +01006USAGE='[-a] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit> | --amend] [-u] [-e] [--author <author>] [[-i | -o] <path>...]'
Junio C Hamano130fcca2006-02-05 00:07:44 -08007SUBDIRECTORY_OK=Yes
Junio C Hamanoae2b0f12005-11-24 00:12:11 -08008. git-sh-setup
Shawn O. Pearce7eff28a2006-12-30 23:32:38 -05009require_work_tree
Linus Torvaldsb33e9662005-07-08 10:57:21 -070010
Junio C Hamanocf7bb582006-02-10 00:45:59 -080011git-rev-parse --verify HEAD >/dev/null 2>&1 || initial_commit=t
Junio C Hamanocf7bb582006-02-10 00:45:59 -080012
13case "$0" in
14*status)
15 status_only=t
16 unmerged_ok_if_status=--unmerged ;;
17*commit)
18 status_only=
19 unmerged_ok_if_status= ;;
20esac
Junio C Hamano130fcca2006-02-05 00:07:44 -080021
22refuse_partial () {
23 echo >&2 "$1"
Junio C Hamano130fcca2006-02-05 00:07:44 -080024 echo >&2 "You might have meant to say 'git commit -i paths...', perhaps?"
25 exit 1
26}
27
Junio C Hamanocf7bb582006-02-10 00:45:59 -080028THIS_INDEX="$GIT_DIR/index"
29NEXT_INDEX="$GIT_DIR/next-index$$"
30rm -f "$NEXT_INDEX"
Junio C Hamano5a798fb2006-02-05 16:08:01 -080031save_index () {
Junio C Hamanocc7d5bc2006-06-29 14:48:22 -070032 cp -p "$THIS_INDEX" "$NEXT_INDEX"
Junio C Hamanocf7bb582006-02-10 00:45:59 -080033}
34
Junio C Hamano5a798fb2006-02-05 16:08:01 -080035run_status () {
Junio C Hamanocf7bb582006-02-10 00:45:59 -080036 # If TMP_INDEX is defined, that means we are doing
37 # "--only" partial commit, and that index file is used
38 # to build the tree for the commit. Otherwise, if
39 # NEXT_INDEX exists, that is the index file used to
40 # make the commit. Otherwise we are using as-is commit
41 # so the regular index file is what we use to compare.
42 if test '' != "$TMP_INDEX"
43 then
Martin Waitz3de63c32006-10-07 21:07:40 +020044 GIT_INDEX_FILE="$TMP_INDEX"
45 export GIT_INDEX_FILE
Junio C Hamanocf7bb582006-02-10 00:45:59 -080046 elif test -f "$NEXT_INDEX"
47 then
Martin Waitz3de63c32006-10-07 21:07:40 +020048 GIT_INDEX_FILE="$NEXT_INDEX"
49 export GIT_INDEX_FILE
Junio C Hamanocf7bb582006-02-10 00:45:59 -080050 fi
51
Martin Waitz3de63c32006-10-07 21:07:40 +020052 case "$status_only" in
53 t) color= ;;
54 *) color=--nocolor ;;
55 esac
56 git-runstatus ${color} \
57 ${verbose:+--verbose} \
58 ${amend:+--amend} \
Johannes Schindelin2074cb02006-09-12 22:45:12 +020059 ${untracked_files:+--untracked}
Junio C Hamano5a798fb2006-02-05 16:08:01 -080060}
61
Junio C Hamanocf7bb582006-02-10 00:45:59 -080062trap '
63 test -z "$TMP_INDEX" || {
64 test -f "$TMP_INDEX" && rm -f "$TMP_INDEX"
65 }
66 rm -f "$NEXT_INDEX"
67' 0
68
69################################################################
70# Command line argument parsing and sanity checking
71
Junio C Hamano130fcca2006-02-05 00:07:44 -080072all=
73also=
Junio C Hamano5a798fb2006-02-05 16:08:01 -080074only=
Junio C Hamano130fcca2006-02-05 00:07:44 -080075logfile=
76use_commit=
Junio C Hamanob4019f02006-03-02 21:04:05 -080077amend=
Jeff Kingcda8ab52006-06-23 09:43:38 -040078edit_flag=
Junio C Hamano130fcca2006-02-05 00:07:44 -080079no_edit=
80log_given=
81log_message=
82verify=t
Nicolas Pitreebd124c2006-12-14 23:15:44 -050083quiet=
Junio C Hamanocf7bb582006-02-10 00:45:59 -080084verbose=
Junio C Hamano130fcca2006-02-05 00:07:44 -080085signoff=
86force_author=
Junio C Hamanobba319b2006-02-14 12:40:20 -080087only_include_assumed=
Matthias Lederhofer443f8332006-05-22 23:02:06 +020088untracked_files=
Junio C Hamano0c091292005-08-08 17:03:14 -070089while case "$#" in 0) break;; esac
Junio C Hamano5fec3ef2005-06-25 02:22:05 -070090do
Martin Waitz3de63c32006-10-07 21:07:40 +020091 case "$1" in
92 -F|--F|-f|--f|--fi|--fil|--file)
93 case "$#" in 1) usage ;; esac
94 shift
95 no_edit=t
96 log_given=t$log_given
97 logfile="$1"
98 shift
99 ;;
100 -F*|-f*)
101 no_edit=t
102 log_given=t$log_given
103 logfile=`expr "z$1" : 'z-[Ff]\(.*\)'`
104 shift
105 ;;
106 --F=*|--f=*|--fi=*|--fil=*|--file=*)
107 no_edit=t
108 log_given=t$log_given
109 logfile=`expr "z$1" : 'z-[^=]*=\(.*\)'`
110 shift
111 ;;
112 -a|--a|--al|--all)
113 all=t
114 shift
115 ;;
116 --au=*|--aut=*|--auth=*|--autho=*|--author=*)
117 force_author=`expr "z$1" : 'z-[^=]*=\(.*\)'`
118 shift
119 ;;
120 --au|--aut|--auth|--autho|--author)
121 case "$#" in 1) usage ;; esac
122 shift
123 force_author="$1"
124 shift
125 ;;
126 -e|--e|--ed|--edi|--edit)
127 edit_flag=t
128 shift
129 ;;
130 -i|--i|--in|--inc|--incl|--inclu|--includ|--include)
131 also=t
132 shift
133 ;;
134 -o|--o|--on|--onl|--only)
135 only=t
136 shift
137 ;;
138 -m|--m|--me|--mes|--mess|--messa|--messag|--message)
139 case "$#" in 1) usage ;; esac
140 shift
141 log_given=m$log_given
142 if test "$log_message" = ''
143 then
144 log_message="$1"
145 else
146 log_message="$log_message
Shawn Pearce68912812006-05-29 04:45:49 -0400147
148$1"
Martin Waitz3de63c32006-10-07 21:07:40 +0200149 fi
150 no_edit=t
151 shift
152 ;;
153 -m*)
154 log_given=m$log_given
155 if test "$log_message" = ''
156 then
157 log_message=`expr "z$1" : 'z-m\(.*\)'`
158 else
159 log_message="$log_message
Shawn Pearce68912812006-05-29 04:45:49 -0400160
Dennis Stosberg8096fae2006-06-27 18:54:26 +0200161`expr "z$1" : 'z-m\(.*\)'`"
Martin Waitz3de63c32006-10-07 21:07:40 +0200162 fi
163 no_edit=t
164 shift
165 ;;
166 --m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*)
167 log_given=m$log_given
168 if test "$log_message" = ''
169 then
170 log_message=`expr "z$1" : 'z-[^=]*=\(.*\)'`
171 else
172 log_message="$log_message
Shawn Pearce68912812006-05-29 04:45:49 -0400173
Dennis Stosberg8096fae2006-06-27 18:54:26 +0200174`expr "z$1" : 'zq-[^=]*=\(.*\)'`"
Martin Waitz3de63c32006-10-07 21:07:40 +0200175 fi
176 no_edit=t
177 shift
178 ;;
179 -n|--n|--no|--no-|--no-v|--no-ve|--no-ver|--no-veri|--no-verif|\
180 --no-verify)
181 verify=
182 shift
183 ;;
184 --a|--am|--ame|--amen|--amend)
185 amend=t
186 log_given=t$log_given
187 use_commit=HEAD
188 shift
189 ;;
190 -c)
191 case "$#" in 1) usage ;; esac
192 shift
193 log_given=t$log_given
194 use_commit="$1"
195 no_edit=
196 shift
197 ;;
198 --ree=*|--reed=*|--reedi=*|--reedit=*|--reedit-=*|--reedit-m=*|\
199 --reedit-me=*|--reedit-mes=*|--reedit-mess=*|--reedit-messa=*|\
200 --reedit-messag=*|--reedit-message=*)
201 log_given=t$log_given
202 use_commit=`expr "z$1" : 'z-[^=]*=\(.*\)'`
203 no_edit=
204 shift
205 ;;
206 --ree|--reed|--reedi|--reedit|--reedit-|--reedit-m|--reedit-me|\
207 --reedit-mes|--reedit-mess|--reedit-messa|--reedit-messag|\
208 --reedit-message)
209 case "$#" in 1) usage ;; esac
210 shift
211 log_given=t$log_given
212 use_commit="$1"
213 no_edit=
214 shift
215 ;;
216 -C)
217 case "$#" in 1) usage ;; esac
218 shift
219 log_given=t$log_given
220 use_commit="$1"
221 no_edit=t
222 shift
223 ;;
224 --reu=*|--reus=*|--reuse=*|--reuse-=*|--reuse-m=*|--reuse-me=*|\
225 --reuse-mes=*|--reuse-mess=*|--reuse-messa=*|--reuse-messag=*|\
226 --reuse-message=*)
227 log_given=t$log_given
228 use_commit=`expr "z$1" : 'z-[^=]*=\(.*\)'`
229 no_edit=t
230 shift
231 ;;
232 --reu|--reus|--reuse|--reuse-|--reuse-m|--reuse-me|--reuse-mes|\
233 --reuse-mess|--reuse-messa|--reuse-messag|--reuse-message)
234 case "$#" in 1) usage ;; esac
235 shift
236 log_given=t$log_given
237 use_commit="$1"
238 no_edit=t
239 shift
240 ;;
241 -s|--s|--si|--sig|--sign|--signo|--signof|--signoff)
242 signoff=t
243 shift
244 ;;
Nicolas Pitreebd124c2006-12-14 23:15:44 -0500245 -q|--q|--qu|--qui|--quie|--quiet)
246 quiet=t
247 shift
248 ;;
Martin Waitz3de63c32006-10-07 21:07:40 +0200249 -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
250 verbose=t
251 shift
252 ;;
253 -u|--u|--un|--unt|--untr|--untra|--untrac|--untrack|--untracke|\
254 --untracked|--untracked-|--untracked-f|--untracked-fi|--untracked-fil|\
255 --untracked-file|--untracked-files)
256 untracked_files=t
257 shift
258 ;;
259 --)
260 shift
261 break
262 ;;
263 -*)
264 usage
265 ;;
266 *)
267 break
268 ;;
269 esac
Junio C Hamano5fec3ef2005-06-25 02:22:05 -0700270done
Jeff Kingcda8ab52006-06-23 09:43:38 -0400271case "$edit_flag" in t) no_edit= ;; esac
Junio C Hamano5fec3ef2005-06-25 02:22:05 -0700272
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800273################################################################
274# Sanity check options
275
Junio C Hamanob4019f02006-03-02 21:04:05 -0800276case "$amend,$initial_commit" in
277t,t)
Martin Waitz3de63c32006-10-07 21:07:40 +0200278 die "You do not have anything to amend." ;;
Junio C Hamanob4019f02006-03-02 21:04:05 -0800279t,)
Martin Waitz3de63c32006-10-07 21:07:40 +0200280 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
281 die "You are in the middle of a merge -- cannot amend."
282 fi ;;
Junio C Hamanob4019f02006-03-02 21:04:05 -0800283esac
284
Junio C Hamano0c091292005-08-08 17:03:14 -0700285case "$log_given" in
286tt*)
Peter Eriksen497171e2007-01-24 20:54:46 +0100287 die "Only one of -c/-C/-F/--amend can be used." ;;
Shawn Pearce68912812006-05-29 04:45:49 -0400288*tm*|*mt*)
Peter Eriksen497171e2007-01-24 20:54:46 +0100289 die "Option -m cannot be combined with -c/-C/-F/--amend." ;;
Junio C Hamano0c091292005-08-08 17:03:14 -0700290esac
291
Junio C Hamano6a746422006-04-20 01:20:56 -0700292case "$#,$also,$only,$amend" in
293*,t,t,*)
Martin Waitz3de63c32006-10-07 21:07:40 +0200294 die "Only one of --include/--only can be used." ;;
Junio C Hamano6a746422006-04-20 01:20:56 -07002950,t,,* | 0,,t,)
Martin Waitz3de63c32006-10-07 21:07:40 +0200296 die "No paths with --include/--only does not make sense." ;;
Junio C Hamano6a746422006-04-20 01:20:56 -07002970,,t,t)
Martin Waitz3de63c32006-10-07 21:07:40 +0200298 only_include_assumed="# Clever... amending the last one with dirty index." ;;
Junio C Hamano6a746422006-04-20 01:20:56 -07002990,,,*)
Martin Waitz3de63c32006-10-07 21:07:40 +0200300 ;;
Junio C Hamano6a746422006-04-20 01:20:56 -0700301*,,,*)
Martin Waitz3de63c32006-10-07 21:07:40 +0200302 only_include_assumed="# Explicit paths specified without -i nor -o; assuming --only paths..."
303 also=
304 ;;
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800305esac
306unset only
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800307case "$all,$also,$#" in
308t,t,*)
309 die "Cannot use -a and -i at the same time." ;;
310t,,[1-9]*)
311 die "Paths with -a does not make sense." ;;
312,t,0)
313 die "No paths with -i does not make sense." ;;
314esac
315
316################################################################
317# Prepare index to have a tree to be committed
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800318
Junio C Hamano130fcca2006-02-05 00:07:44 -0800319case "$all,$also" in
Junio C Hamano130fcca2006-02-05 00:07:44 -0800320t,)
Fredrik Kuivinen755b99d2007-02-22 21:28:12 +0100321 if test ! -f "$THIS_INDEX"
322 then
323 die 'nothing to commit (use "git add file1 file2" to include for commit)'
324 fi
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800325 save_index &&
Junio C Hamano130fcca2006-02-05 00:07:44 -0800326 (
Junio C Hamano514c09f2007-01-12 12:49:05 -0800327 cd_to_toplevel &&
328 GIT_INDEX_FILE="$NEXT_INDEX" &&
329 export GIT_INDEX_FILE &&
Junio C Hamano130fcca2006-02-05 00:07:44 -0800330 git-diff-files --name-only -z |
331 git-update-index --remove -z --stdin
Junio C Hamano514c09f2007-01-12 12:49:05 -0800332 ) || exit
Junio C Hamano130fcca2006-02-05 00:07:44 -0800333 ;;
334,t)
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800335 save_index &&
Junio C Hamanobba319b2006-02-14 12:40:20 -0800336 git-ls-files --error-unmatch -- "$@" >/dev/null || exit
337
Junio C Hamano130fcca2006-02-05 00:07:44 -0800338 git-diff-files --name-only -z -- "$@" |
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800339 (
Junio C Hamano514c09f2007-01-12 12:49:05 -0800340 cd_to_toplevel &&
341 GIT_INDEX_FILE="$NEXT_INDEX" &&
342 export GIT_INDEX_FILE &&
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800343 git-update-index --remove -z --stdin
Junio C Hamano514c09f2007-01-12 12:49:05 -0800344 ) || exit
Junio C Hamano22cff6a2005-08-16 18:08:19 -0700345 ;;
Junio C Hamano130fcca2006-02-05 00:07:44 -0800346,)
347 case "$#" in
348 0)
Martin Waitz3de63c32006-10-07 21:07:40 +0200349 ;; # commit as-is
Junio C Hamano130fcca2006-02-05 00:07:44 -0800350 *)
Martin Waitz3de63c32006-10-07 21:07:40 +0200351 if test -f "$GIT_DIR/MERGE_HEAD"
352 then
353 refuse_partial "Cannot do a partial commit during a merge."
354 fi
355 TMP_INDEX="$GIT_DIR/tmp-index$$"
Martin Waitz3de63c32006-10-07 21:07:40 +0200356 commit_only=`git-ls-files --error-unmatch -- "$@"` || exit
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800357
Junio C Hamano158d0572006-12-09 22:32:43 -0800358 # Build a temporary index and update the real index
Martin Waitz3de63c32006-10-07 21:07:40 +0200359 # the same way.
360 if test -z "$initial_commit"
361 then
362 cp "$THIS_INDEX" "$TMP_INDEX"
363 GIT_INDEX_FILE="$TMP_INDEX" git-read-tree -m HEAD
364 else
365 rm -f "$TMP_INDEX"
366 fi || exit
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800367
Martin Waitz3de63c32006-10-07 21:07:40 +0200368 echo "$commit_only" |
369 GIT_INDEX_FILE="$TMP_INDEX" \
370 git-update-index --add --remove --stdin &&
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800371
Martin Waitz3de63c32006-10-07 21:07:40 +0200372 save_index &&
373 echo "$commit_only" |
374 (
375 GIT_INDEX_FILE="$NEXT_INDEX"
376 export GIT_INDEX_FILE
377 git-update-index --remove --stdin
378 ) || exit
379 ;;
Junio C Hamano130fcca2006-02-05 00:07:44 -0800380 esac
Junio C Hamanof678dd12005-11-25 13:33:14 -0800381 ;;
Junio C Hamano130fcca2006-02-05 00:07:44 -0800382esac
383
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800384################################################################
385# If we do as-is commit, the index file will be THIS_INDEX,
386# otherwise NEXT_INDEX after we make this commit. We leave
387# the index as is if we abort.
Junio C Hamano0c091292005-08-08 17:03:14 -0700388
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800389if test -f "$NEXT_INDEX"
Junio C Hamano130fcca2006-02-05 00:07:44 -0800390then
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800391 USE_INDEX="$NEXT_INDEX"
392else
393 USE_INDEX="$THIS_INDEX"
Junio C Hamano130fcca2006-02-05 00:07:44 -0800394fi
395
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800396GIT_INDEX_FILE="$USE_INDEX" \
Martin Waitz3de63c32006-10-07 21:07:40 +0200397 git-update-index -q $unmerged_ok_if_status --refresh || exit
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800398
399################################################################
400# If the request is status, just show it and exit.
401
402case "$0" in
403*status)
404 run_status
405 exit $?
406esac
407
408################################################################
409# Grab commit message, write out tree and make commit.
410
Junio C Hamano130fcca2006-02-05 00:07:44 -0800411if test t = "$verify" && test -x "$GIT_DIR"/hooks/pre-commit
412then
413 if test "$TMP_INDEX"
414 then
415 GIT_INDEX_FILE="$TMP_INDEX" "$GIT_DIR"/hooks/pre-commit
416 else
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800417 GIT_INDEX_FILE="$USE_INDEX" "$GIT_DIR"/hooks/pre-commit
Junio C Hamano130fcca2006-02-05 00:07:44 -0800418 fi || exit
419fi
Junio C Hamano0cfe1d32005-08-12 23:39:15 -0700420
Junio C Hamanoaba2da12005-08-25 18:57:35 -0700421if test "$log_message" != ''
422then
423 echo "$log_message"
424elif test "$logfile" != ""
425then
426 if test "$logfile" = -
427 then
428 test -t 0 &&
429 echo >&2 "(reading log message from standard input)"
430 cat
431 else
432 cat <"$logfile"
433 fi
434elif test "$use_commit" != ""
435then
Tom Princee0d10e12007-01-28 16:16:53 -0800436 encoding=$(git config i18n.commitencoding || echo UTF-8)
Junio C Hamano5ac27152007-01-13 13:33:07 -0800437 git show -s --pretty=raw --encoding="$encoding" "$use_commit" |
438 sed -e '1,/^$/d' -e 's/^ //'
Luben Tuikova9cb3c62006-10-12 14:52:42 -0700439elif test -f "$GIT_DIR/MERGE_MSG"
Junio C Hamanoe5215802005-11-01 22:01:28 -0800440then
441 cat "$GIT_DIR/MERGE_MSG"
Junio C Hamano7d0c6882006-06-23 01:37:02 -0700442elif test -f "$GIT_DIR/SQUASH_MSG"
443then
444 cat "$GIT_DIR/SQUASH_MSG"
Santi_Béjarf8e2c542005-10-09 17:30:19 -0700445fi | git-stripspace >"$GIT_DIR"/COMMIT_EDITMSG
Junio C Hamano2d569932005-08-31 17:15:25 -0700446
447case "$signoff" in
448t)
Junio C Hamanodbaa06a2007-01-29 01:06:27 -0800449 need_blank_before_signoff=
450 tail -n 1 "$GIT_DIR"/COMMIT_EDITMSG |
451 grep 'Signed-off-by:' >/dev/null || need_blank_before_signoff=yes
Junio C Hamanof6413392005-10-03 23:49:46 -0700452 {
Junio C Hamanodbaa06a2007-01-29 01:06:27 -0800453 test -z "$need_blank_before_signoff" || echo
Junio C Hamanof6413392005-10-03 23:49:46 -0700454 git-var GIT_COMMITTER_IDENT | sed -e '
455 s/>.*/>/
456 s/^/Signed-off-by: /
457 '
Santi_Béjarf8e2c542005-10-09 17:30:19 -0700458 } >>"$GIT_DIR"/COMMIT_EDITMSG
Junio C Hamano2d569932005-08-31 17:15:25 -0700459 ;;
460esac
461
Junio C Hamano475443c2006-04-12 11:45:18 -0700462if test -f "$GIT_DIR/MERGE_HEAD" && test -z "$no_edit"; then
Junio C Hamano2d569932005-08-31 17:15:25 -0700463 echo "#"
Alex Riesenb6ae5402006-01-05 12:44:59 +0100464 echo "# It looks like you may be committing a MERGE."
Junio C Hamano2d569932005-08-31 17:15:25 -0700465 echo "# If this is not correct, please remove the file"
466 echo "# $GIT_DIR/MERGE_HEAD"
467 echo "# and try again"
468 echo "#"
Santi_Béjarf8e2c542005-10-09 17:30:19 -0700469fi >>"$GIT_DIR"/COMMIT_EDITMSG
Junio C Hamanoaba2da12005-08-25 18:57:35 -0700470
Junio C Hamano130fcca2006-02-05 00:07:44 -0800471# Author
Junio C Hamano83e24dc2007-01-22 13:03:31 -0800472if test '' != "$use_commit"
Junio C Hamano130fcca2006-02-05 00:07:44 -0800473then
474 pick_author_script='
475 /^author /{
476 s/'\''/'\''\\'\'\''/g
477 h
478 s/^author \([^<]*\) <[^>]*> .*$/\1/
479 s/'\''/'\''\'\'\''/g
480 s/.*/GIT_AUTHOR_NAME='\''&'\''/p
481
482 g
483 s/^author [^<]* <\([^>]*\)> .*$/\1/
484 s/'\''/'\''\'\'\''/g
485 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
486
487 g
488 s/^author [^<]* <[^>]*> \(.*\)$/\1/
489 s/'\''/'\''\'\'\''/g
490 s/.*/GIT_AUTHOR_DATE='\''&'\''/p
491
492 q
493 }
494 '
Tom Princee0d10e12007-01-28 16:16:53 -0800495 encoding=$(git config i18n.commitencoding || echo UTF-8)
Junio C Hamano5ac27152007-01-13 13:33:07 -0800496 set_author_env=`git show -s --pretty=raw --encoding="$encoding" "$use_commit" |
Junio C Hamano130fcca2006-02-05 00:07:44 -0800497 LANG=C LC_ALL=C sed -ne "$pick_author_script"`
498 eval "$set_author_env"
499 export GIT_AUTHOR_NAME
500 export GIT_AUTHOR_EMAIL
501 export GIT_AUTHOR_DATE
Junio C Hamano130fcca2006-02-05 00:07:44 -0800502fi
Junio C Hamano83e24dc2007-01-22 13:03:31 -0800503if test '' != "$force_author"
504then
505 GIT_AUTHOR_NAME=`expr "z$force_author" : 'z\(.*[^ ]\) *<.*'` &&
506 GIT_AUTHOR_EMAIL=`expr "z$force_author" : '.*\(<.*\)'` &&
507 test '' != "$GIT_AUTHOR_NAME" &&
508 test '' != "$GIT_AUTHOR_EMAIL" ||
509 die "malformed --author parameter"
510 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
511fi
Junio C Hamano130fcca2006-02-05 00:07:44 -0800512
Linus Torvalds96069cf2005-06-14 10:20:14 -0700513PARENTS="-p HEAD"
Junio C Hamano130fcca2006-02-05 00:07:44 -0800514if test -z "$initial_commit"
Junio C Hamano8098a172005-09-30 14:26:57 -0700515then
Shawn Pearcea3a733e2006-07-10 22:48:47 -0400516 rloga='commit'
Junio C Hamano5fec3ef2005-06-25 02:22:05 -0700517 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
Shawn Pearcea3a733e2006-07-10 22:48:47 -0400518 rloga='commit (merge)'
Junio C Hamano91063bb2005-09-08 13:47:12 -0700519 PARENTS="-p HEAD "`sed -e 's/^/-p /' "$GIT_DIR/MERGE_HEAD"`
Junio C Hamanob4019f02006-03-02 21:04:05 -0800520 elif test -n "$amend"; then
Shawn Pearcea3a733e2006-07-10 22:48:47 -0400521 rloga='commit (amend)'
Junio C Hamanob4019f02006-03-02 21:04:05 -0800522 PARENTS=$(git-cat-file commit HEAD |
523 sed -n -e '/^$/q' -e 's/^parent /-p /p')
Junio C Hamanoaba2da12005-08-25 18:57:35 -0700524 fi
Junio C Hamanocede7522006-09-27 02:06:31 -0700525 current="$(git-rev-parse --verify HEAD)"
Junio C Hamano8098a172005-09-30 14:26:57 -0700526else
527 if [ -z "$(git-ls-files)" ]; then
Shawn O. Pearceaeb80c72006-12-15 21:53:09 -0500528 echo >&2 'nothing to commit (use "git add file1 file2" to include for commit)'
Junio C Hamano8098a172005-09-30 14:26:57 -0700529 exit 1
530 fi
531 PARENTS=""
Shawn Pearcea3a733e2006-07-10 22:48:47 -0400532 rloga='commit (initial)'
Junio C Hamanocede7522006-09-27 02:06:31 -0700533 current=''
Linus Torvalds96069cf2005-06-14 10:20:14 -0700534fi
Junio C Hamano23913dc2007-01-19 17:12:11 -0800535set_reflog_action "$rloga"
Junio C Hamano130fcca2006-02-05 00:07:44 -0800536
Junio C Hamano475443c2006-04-12 11:45:18 -0700537if test -z "$no_edit"
538then
539 {
Martin Waitz88a15312006-05-26 01:42:18 +0200540 echo ""
541 echo "# Please enter the commit message for your changes."
542 echo "# (Comment lines starting with '#' will not be included)"
Junio C Hamano475443c2006-04-12 11:45:18 -0700543 test -z "$only_include_assumed" || echo "$only_include_assumed"
544 run_status
545 } >>"$GIT_DIR"/COMMIT_EDITMSG
546else
547 # we need to check if there is anything to commit
548 run_status >/dev/null
549fi
Junio C Hamano85884522006-03-04 20:36:28 -0800550if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" -a -z "$amend" ]
Linus Torvaldsa3e870f2005-05-30 12:51:00 -0700551then
Junio C Hamano7d0c6882006-06-23 01:37:02 -0700552 rm -f "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG"
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800553 run_status
Linus Torvaldsa3e870f2005-05-30 12:51:00 -0700554 exit 1
555fi
Junio C Hamano475443c2006-04-12 11:45:18 -0700556
Junio C Hamano0c091292005-08-08 17:03:14 -0700557case "$no_edit" in
Junio C Hamano5fec3ef2005-06-25 02:22:05 -0700558'')
Junio C Hamano7334f062006-02-04 22:10:32 -0800559 case "${VISUAL:-$EDITOR},$TERM" in
560 ,dumb)
561 echo >&2 "Terminal is dumb but no VISUAL nor EDITOR defined."
562 echo >&2 "Please supply the commit log message using either"
563 echo >&2 "-m or -F option. A boilerplate log message has"
564 echo >&2 "been prepared in $GIT_DIR/COMMIT_EDITMSG"
Junio C Hamano130fcca2006-02-05 00:07:44 -0800565 exit 1
566 ;;
Junio C Hamano7334f062006-02-04 22:10:32 -0800567 esac
Seanec4e69c2006-05-13 23:09:32 -0400568 git-var GIT_AUTHOR_IDENT > /dev/null || die
569 git-var GIT_COMMITTER_IDENT > /dev/null || die
Santi_Béjarf8e2c542005-10-09 17:30:19 -0700570 ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR/COMMIT_EDITMSG"
Junio C Hamano5fec3ef2005-06-25 02:22:05 -0700571 ;;
572esac
Junio C Hamano89e2c5f2005-08-18 17:20:08 -0700573
574case "$verify" in
575t)
576 if test -x "$GIT_DIR"/hooks/commit-msg
577 then
Santi_Béjarf8e2c542005-10-09 17:30:19 -0700578 "$GIT_DIR"/hooks/commit-msg "$GIT_DIR"/COMMIT_EDITMSG || exit
Junio C Hamano89e2c5f2005-08-18 17:20:08 -0700579 fi
580esac
581
Yann Dirson29f4ad82006-06-24 00:04:05 +0200582if test -z "$no_edit"
583then
584 sed -e '
585 /^diff --git a\/.*/{
586 s///
587 q
588 }
589 /^#/d
590 ' "$GIT_DIR"/COMMIT_EDITMSG
591else
592 cat "$GIT_DIR"/COMMIT_EDITMSG
593fi |
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800594git-stripspace >"$GIT_DIR"/COMMIT_MSG
Santi_Béjarf8e2c542005-10-09 17:30:19 -0700595
596if cnt=`grep -v -i '^Signed-off-by' "$GIT_DIR"/COMMIT_MSG |
597 git-stripspace |
598 wc -l` &&
599 test 0 -lt $cnt
Junio C Hamano0c091292005-08-08 17:03:14 -0700600then
Junio C Hamano130fcca2006-02-05 00:07:44 -0800601 if test -z "$TMP_INDEX"
602 then
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800603 tree=$(GIT_INDEX_FILE="$USE_INDEX" git-write-tree)
Junio C Hamano130fcca2006-02-05 00:07:44 -0800604 else
605 tree=$(GIT_INDEX_FILE="$TMP_INDEX" git-write-tree) &&
606 rm -f "$TMP_INDEX"
607 fi &&
Santi_Béjarf8e2c542005-10-09 17:30:19 -0700608 commit=$(cat "$GIT_DIR"/COMMIT_MSG | git-commit-tree $tree $PARENTS) &&
Shawn Pearce67644a42006-05-19 05:16:18 -0400609 rlogm=$(sed -e 1q "$GIT_DIR"/COMMIT_MSG) &&
Junio C Hamano23913dc2007-01-19 17:12:11 -0800610 git-update-ref -m "$GIT_REFLOG_ACTION: $rlogm" HEAD $commit "$current" &&
Luben Tuikova9cb3c62006-10-12 14:52:42 -0700611 rm -f -- "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/MERGE_MSG" &&
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800612 if test -f "$NEXT_INDEX"
613 then
614 mv "$NEXT_INDEX" "$THIS_INDEX"
615 else
616 : ;# happy
617 fi
Junio C Hamano0c091292005-08-08 17:03:14 -0700618else
619 echo >&2 "* no commit message? aborting commit."
620 false
621fi
Linus Torvalds170241b2005-06-19 19:57:01 -0700622ret="$?"
Junio C Hamano7d0c6882006-06-23 01:37:02 -0700623rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG"
Junio C Hamano1536dd9c62006-02-11 18:55:43 -0800624if test -d "$GIT_DIR/rr-cache"
625then
626 git-rerere
627fi
Junio C Hamano89e2c5f2005-08-18 17:20:08 -0700628
Nicolas Pitreebd124c2006-12-14 23:15:44 -0500629if test "$ret" = 0
Junio C Hamano89e2c5f2005-08-18 17:20:08 -0700630then
Nicolas Pitreebd124c2006-12-14 23:15:44 -0500631 if test -x "$GIT_DIR"/hooks/post-commit
632 then
633 "$GIT_DIR"/hooks/post-commit
634 fi
635 if test -z "$quiet"
636 then
637 echo "Created${initial_commit:+ initial} commit $commit"
Michael Loeffler521f9c42007-01-08 20:23:13 +0100638 git-diff-tree --shortstat --summary --root --no-commit-id HEAD --
Nicolas Pitreebd124c2006-12-14 23:15:44 -0500639 fi
Junio C Hamano89e2c5f2005-08-18 17:20:08 -0700640fi
Junio C Hamano61f5cb72006-10-24 21:48:55 -0700641
Linus Torvalds170241b2005-06-19 19:57:01 -0700642exit "$ret"