blob: 04aad5e5da6fad46bc71c859286615c2f6ce11ab [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
Matthias Lederhofer443f8332006-05-22 23:02:06 +02006USAGE='[-a] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit>] [-u] [--amend] [-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
Linus Torvaldsb33e9662005-07-08 10:57:21 -07009
Junio C Hamanocf7bb582006-02-10 00:45:59 -080010git-rev-parse --verify HEAD >/dev/null 2>&1 || initial_commit=t
Junio C Hamanocf7bb582006-02-10 00:45:59 -080011
12case "$0" in
13*status)
14 status_only=t
15 unmerged_ok_if_status=--unmerged ;;
16*commit)
17 status_only=
18 unmerged_ok_if_status= ;;
19esac
Junio C Hamano130fcca2006-02-05 00:07:44 -080020
21refuse_partial () {
22 echo >&2 "$1"
Junio C Hamano130fcca2006-02-05 00:07:44 -080023 echo >&2 "You might have meant to say 'git commit -i paths...', perhaps?"
24 exit 1
25}
26
Junio C Hamanocf7bb582006-02-10 00:45:59 -080027THIS_INDEX="$GIT_DIR/index"
28NEXT_INDEX="$GIT_DIR/next-index$$"
29rm -f "$NEXT_INDEX"
Junio C Hamano5a798fb2006-02-05 16:08:01 -080030save_index () {
Junio C Hamanocc7d5bc2006-06-29 14:48:22 -070031 cp -p "$THIS_INDEX" "$NEXT_INDEX"
Junio C Hamanocf7bb582006-02-10 00:45:59 -080032}
33
Junio C Hamano5a798fb2006-02-05 16:08:01 -080034run_status () {
Junio C Hamanocf7bb582006-02-10 00:45:59 -080035 # If TMP_INDEX is defined, that means we are doing
36 # "--only" partial commit, and that index file is used
37 # to build the tree for the commit. Otherwise, if
38 # NEXT_INDEX exists, that is the index file used to
39 # make the commit. Otherwise we are using as-is commit
40 # so the regular index file is what we use to compare.
41 if test '' != "$TMP_INDEX"
42 then
Martin Waitz3de63c32006-10-07 21:07:40 +020043 GIT_INDEX_FILE="$TMP_INDEX"
44 export GIT_INDEX_FILE
Junio C Hamanocf7bb582006-02-10 00:45:59 -080045 elif test -f "$NEXT_INDEX"
46 then
Martin Waitz3de63c32006-10-07 21:07:40 +020047 GIT_INDEX_FILE="$NEXT_INDEX"
48 export GIT_INDEX_FILE
Junio C Hamanocf7bb582006-02-10 00:45:59 -080049 fi
50
Martin Waitz3de63c32006-10-07 21:07:40 +020051 case "$status_only" in
52 t) color= ;;
53 *) color=--nocolor ;;
54 esac
55 git-runstatus ${color} \
56 ${verbose:+--verbose} \
57 ${amend:+--amend} \
Johannes Schindelin2074cb02006-09-12 22:45:12 +020058 ${untracked_files:+--untracked}
Junio C Hamano5a798fb2006-02-05 16:08:01 -080059}
60
Junio C Hamanocf7bb582006-02-10 00:45:59 -080061trap '
62 test -z "$TMP_INDEX" || {
63 test -f "$TMP_INDEX" && rm -f "$TMP_INDEX"
64 }
65 rm -f "$NEXT_INDEX"
66' 0
67
68################################################################
69# Command line argument parsing and sanity checking
70
Junio C Hamano130fcca2006-02-05 00:07:44 -080071all=
72also=
Junio C Hamano5a798fb2006-02-05 16:08:01 -080073only=
Junio C Hamano130fcca2006-02-05 00:07:44 -080074logfile=
75use_commit=
Junio C Hamanob4019f02006-03-02 21:04:05 -080076amend=
Jeff Kingcda8ab52006-06-23 09:43:38 -040077edit_flag=
Junio C Hamano130fcca2006-02-05 00:07:44 -080078no_edit=
79log_given=
80log_message=
81verify=t
Nicolas Pitreebd124c2006-12-14 23:15:44 -050082quiet=
Junio C Hamanocf7bb582006-02-10 00:45:59 -080083verbose=
Junio C Hamano130fcca2006-02-05 00:07:44 -080084signoff=
85force_author=
Junio C Hamanobba319b2006-02-14 12:40:20 -080086only_include_assumed=
Matthias Lederhofer443f8332006-05-22 23:02:06 +020087untracked_files=
Junio C Hamano0c091292005-08-08 17:03:14 -070088while case "$#" in 0) break;; esac
Junio C Hamano5fec3ef2005-06-25 02:22:05 -070089do
Martin Waitz3de63c32006-10-07 21:07:40 +020090 case "$1" in
91 -F|--F|-f|--f|--fi|--fil|--file)
92 case "$#" in 1) usage ;; esac
93 shift
94 no_edit=t
95 log_given=t$log_given
96 logfile="$1"
97 shift
98 ;;
99 -F*|-f*)
100 no_edit=t
101 log_given=t$log_given
102 logfile=`expr "z$1" : 'z-[Ff]\(.*\)'`
103 shift
104 ;;
105 --F=*|--f=*|--fi=*|--fil=*|--file=*)
106 no_edit=t
107 log_given=t$log_given
108 logfile=`expr "z$1" : 'z-[^=]*=\(.*\)'`
109 shift
110 ;;
111 -a|--a|--al|--all)
112 all=t
113 shift
114 ;;
115 --au=*|--aut=*|--auth=*|--autho=*|--author=*)
116 force_author=`expr "z$1" : 'z-[^=]*=\(.*\)'`
117 shift
118 ;;
119 --au|--aut|--auth|--autho|--author)
120 case "$#" in 1) usage ;; esac
121 shift
122 force_author="$1"
123 shift
124 ;;
125 -e|--e|--ed|--edi|--edit)
126 edit_flag=t
127 shift
128 ;;
129 -i|--i|--in|--inc|--incl|--inclu|--includ|--include)
130 also=t
131 shift
132 ;;
133 -o|--o|--on|--onl|--only)
134 only=t
135 shift
136 ;;
137 -m|--m|--me|--mes|--mess|--messa|--messag|--message)
138 case "$#" in 1) usage ;; esac
139 shift
140 log_given=m$log_given
141 if test "$log_message" = ''
142 then
143 log_message="$1"
144 else
145 log_message="$log_message
Shawn Pearce68912812006-05-29 04:45:49 -0400146
147$1"
Martin Waitz3de63c32006-10-07 21:07:40 +0200148 fi
149 no_edit=t
150 shift
151 ;;
152 -m*)
153 log_given=m$log_given
154 if test "$log_message" = ''
155 then
156 log_message=`expr "z$1" : 'z-m\(.*\)'`
157 else
158 log_message="$log_message
Shawn Pearce68912812006-05-29 04:45:49 -0400159
Dennis Stosberg8096fae2006-06-27 18:54:26 +0200160`expr "z$1" : 'z-m\(.*\)'`"
Martin Waitz3de63c32006-10-07 21:07:40 +0200161 fi
162 no_edit=t
163 shift
164 ;;
165 --m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*)
166 log_given=m$log_given
167 if test "$log_message" = ''
168 then
169 log_message=`expr "z$1" : 'z-[^=]*=\(.*\)'`
170 else
171 log_message="$log_message
Shawn Pearce68912812006-05-29 04:45:49 -0400172
Dennis Stosberg8096fae2006-06-27 18:54:26 +0200173`expr "z$1" : 'zq-[^=]*=\(.*\)'`"
Martin Waitz3de63c32006-10-07 21:07:40 +0200174 fi
175 no_edit=t
176 shift
177 ;;
178 -n|--n|--no|--no-|--no-v|--no-ve|--no-ver|--no-veri|--no-verif|\
179 --no-verify)
180 verify=
181 shift
182 ;;
183 --a|--am|--ame|--amen|--amend)
184 amend=t
185 log_given=t$log_given
186 use_commit=HEAD
187 shift
188 ;;
189 -c)
190 case "$#" in 1) usage ;; esac
191 shift
192 log_given=t$log_given
193 use_commit="$1"
194 no_edit=
195 shift
196 ;;
197 --ree=*|--reed=*|--reedi=*|--reedit=*|--reedit-=*|--reedit-m=*|\
198 --reedit-me=*|--reedit-mes=*|--reedit-mess=*|--reedit-messa=*|\
199 --reedit-messag=*|--reedit-message=*)
200 log_given=t$log_given
201 use_commit=`expr "z$1" : 'z-[^=]*=\(.*\)'`
202 no_edit=
203 shift
204 ;;
205 --ree|--reed|--reedi|--reedit|--reedit-|--reedit-m|--reedit-me|\
206 --reedit-mes|--reedit-mess|--reedit-messa|--reedit-messag|\
207 --reedit-message)
208 case "$#" in 1) usage ;; esac
209 shift
210 log_given=t$log_given
211 use_commit="$1"
212 no_edit=
213 shift
214 ;;
215 -C)
216 case "$#" in 1) usage ;; esac
217 shift
218 log_given=t$log_given
219 use_commit="$1"
220 no_edit=t
221 shift
222 ;;
223 --reu=*|--reus=*|--reuse=*|--reuse-=*|--reuse-m=*|--reuse-me=*|\
224 --reuse-mes=*|--reuse-mess=*|--reuse-messa=*|--reuse-messag=*|\
225 --reuse-message=*)
226 log_given=t$log_given
227 use_commit=`expr "z$1" : 'z-[^=]*=\(.*\)'`
228 no_edit=t
229 shift
230 ;;
231 --reu|--reus|--reuse|--reuse-|--reuse-m|--reuse-me|--reuse-mes|\
232 --reuse-mess|--reuse-messa|--reuse-messag|--reuse-message)
233 case "$#" in 1) usage ;; esac
234 shift
235 log_given=t$log_given
236 use_commit="$1"
237 no_edit=t
238 shift
239 ;;
240 -s|--s|--si|--sig|--sign|--signo|--signof|--signoff)
241 signoff=t
242 shift
243 ;;
Nicolas Pitreebd124c2006-12-14 23:15:44 -0500244 -q|--q|--qu|--qui|--quie|--quiet)
245 quiet=t
246 shift
247 ;;
Martin Waitz3de63c32006-10-07 21:07:40 +0200248 -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
249 verbose=t
250 shift
251 ;;
252 -u|--u|--un|--unt|--untr|--untra|--untrac|--untrack|--untracke|\
253 --untracked|--untracked-|--untracked-f|--untracked-fi|--untracked-fil|\
254 --untracked-file|--untracked-files)
255 untracked_files=t
256 shift
257 ;;
258 --)
259 shift
260 break
261 ;;
262 -*)
263 usage
264 ;;
265 *)
266 break
267 ;;
268 esac
Junio C Hamano5fec3ef2005-06-25 02:22:05 -0700269done
Jeff Kingcda8ab52006-06-23 09:43:38 -0400270case "$edit_flag" in t) no_edit= ;; esac
Junio C Hamano5fec3ef2005-06-25 02:22:05 -0700271
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800272################################################################
273# Sanity check options
274
Junio C Hamanob4019f02006-03-02 21:04:05 -0800275case "$amend,$initial_commit" in
276t,t)
Martin Waitz3de63c32006-10-07 21:07:40 +0200277 die "You do not have anything to amend." ;;
Junio C Hamanob4019f02006-03-02 21:04:05 -0800278t,)
Martin Waitz3de63c32006-10-07 21:07:40 +0200279 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
280 die "You are in the middle of a merge -- cannot amend."
281 fi ;;
Junio C Hamanob4019f02006-03-02 21:04:05 -0800282esac
283
Junio C Hamano0c091292005-08-08 17:03:14 -0700284case "$log_given" in
285tt*)
Martin Waitz3de63c32006-10-07 21:07:40 +0200286 die "Only one of -c/-C/-F can be used." ;;
Shawn Pearce68912812006-05-29 04:45:49 -0400287*tm*|*mt*)
Martin Waitz3de63c32006-10-07 21:07:40 +0200288 die "Option -m cannot be combined with -c/-C/-F." ;;
Junio C Hamano0c091292005-08-08 17:03:14 -0700289esac
290
Junio C Hamano6a746422006-04-20 01:20:56 -0700291case "$#,$also,$only,$amend" in
292*,t,t,*)
Martin Waitz3de63c32006-10-07 21:07:40 +0200293 die "Only one of --include/--only can be used." ;;
Junio C Hamano6a746422006-04-20 01:20:56 -07002940,t,,* | 0,,t,)
Martin Waitz3de63c32006-10-07 21:07:40 +0200295 die "No paths with --include/--only does not make sense." ;;
Junio C Hamano6a746422006-04-20 01:20:56 -07002960,,t,t)
Martin Waitz3de63c32006-10-07 21:07:40 +0200297 only_include_assumed="# Clever... amending the last one with dirty index." ;;
Junio C Hamano6a746422006-04-20 01:20:56 -07002980,,,*)
Martin Waitz3de63c32006-10-07 21:07:40 +0200299 ;;
Junio C Hamano6a746422006-04-20 01:20:56 -0700300*,,,*)
Martin Waitz3de63c32006-10-07 21:07:40 +0200301 only_include_assumed="# Explicit paths specified without -i nor -o; assuming --only paths..."
302 also=
303 ;;
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800304esac
305unset only
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800306case "$all,$also,$#" in
307t,t,*)
308 die "Cannot use -a and -i at the same time." ;;
309t,,[1-9]*)
310 die "Paths with -a does not make sense." ;;
311,t,0)
312 die "No paths with -i does not make sense." ;;
313esac
314
315################################################################
316# Prepare index to have a tree to be committed
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800317
Junio C Hamano130fcca2006-02-05 00:07:44 -0800318TOP=`git-rev-parse --show-cdup`
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800319if test -z "$TOP"
320then
321 TOP=./
322fi
Junio C Hamano130fcca2006-02-05 00:07:44 -0800323
324case "$all,$also" in
Junio C Hamano130fcca2006-02-05 00:07:44 -0800325t,)
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800326 save_index &&
Junio C Hamano130fcca2006-02-05 00:07:44 -0800327 (
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800328 cd "$TOP"
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800329 GIT_INDEX_FILE="$NEXT_INDEX"
330 export GIT_INDEX_FILE
Junio C Hamano130fcca2006-02-05 00:07:44 -0800331 git-diff-files --name-only -z |
332 git-update-index --remove -z --stdin
333 )
334 ;;
335,t)
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800336 save_index &&
Junio C Hamanobba319b2006-02-14 12:40:20 -0800337 git-ls-files --error-unmatch -- "$@" >/dev/null || exit
338
Junio C Hamano130fcca2006-02-05 00:07:44 -0800339 git-diff-files --name-only -z -- "$@" |
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800340 (
341 cd "$TOP"
342 GIT_INDEX_FILE="$NEXT_INDEX"
343 export GIT_INDEX_FILE
344 git-update-index --remove -z --stdin
345 )
Junio C Hamano22cff6a2005-08-16 18:08:19 -0700346 ;;
Junio C Hamano130fcca2006-02-05 00:07:44 -0800347,)
348 case "$#" in
349 0)
Martin Waitz3de63c32006-10-07 21:07:40 +0200350 ;; # commit as-is
Junio C Hamano130fcca2006-02-05 00:07:44 -0800351 *)
Martin Waitz3de63c32006-10-07 21:07:40 +0200352 if test -f "$GIT_DIR/MERGE_HEAD"
353 then
354 refuse_partial "Cannot do a partial commit during a merge."
355 fi
356 TMP_INDEX="$GIT_DIR/tmp-index$$"
Martin Waitz3de63c32006-10-07 21:07:40 +0200357 commit_only=`git-ls-files --error-unmatch -- "$@"` || exit
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800358
Junio C Hamano158d0572006-12-09 22:32:43 -0800359 # Build a temporary index and update the real index
Martin Waitz3de63c32006-10-07 21:07:40 +0200360 # the same way.
361 if test -z "$initial_commit"
362 then
363 cp "$THIS_INDEX" "$TMP_INDEX"
364 GIT_INDEX_FILE="$TMP_INDEX" git-read-tree -m HEAD
365 else
366 rm -f "$TMP_INDEX"
367 fi || exit
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800368
Martin Waitz3de63c32006-10-07 21:07:40 +0200369 echo "$commit_only" |
370 GIT_INDEX_FILE="$TMP_INDEX" \
371 git-update-index --add --remove --stdin &&
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800372
Martin Waitz3de63c32006-10-07 21:07:40 +0200373 save_index &&
374 echo "$commit_only" |
375 (
376 GIT_INDEX_FILE="$NEXT_INDEX"
377 export GIT_INDEX_FILE
378 git-update-index --remove --stdin
379 ) || exit
380 ;;
Junio C Hamano130fcca2006-02-05 00:07:44 -0800381 esac
Junio C Hamanof678dd12005-11-25 13:33:14 -0800382 ;;
Junio C Hamano130fcca2006-02-05 00:07:44 -0800383esac
384
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800385################################################################
386# If we do as-is commit, the index file will be THIS_INDEX,
387# otherwise NEXT_INDEX after we make this commit. We leave
388# the index as is if we abort.
Junio C Hamano0c091292005-08-08 17:03:14 -0700389
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800390if test -f "$NEXT_INDEX"
Junio C Hamano130fcca2006-02-05 00:07:44 -0800391then
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800392 USE_INDEX="$NEXT_INDEX"
393else
394 USE_INDEX="$THIS_INDEX"
Junio C Hamano130fcca2006-02-05 00:07:44 -0800395fi
396
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800397GIT_INDEX_FILE="$USE_INDEX" \
Martin Waitz3de63c32006-10-07 21:07:40 +0200398 git-update-index -q $unmerged_ok_if_status --refresh || exit
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800399
400################################################################
401# If the request is status, just show it and exit.
402
403case "$0" in
404*status)
405 run_status
406 exit $?
407esac
408
409################################################################
410# Grab commit message, write out tree and make commit.
411
Junio C Hamano130fcca2006-02-05 00:07:44 -0800412if test t = "$verify" && test -x "$GIT_DIR"/hooks/pre-commit
413then
414 if test "$TMP_INDEX"
415 then
416 GIT_INDEX_FILE="$TMP_INDEX" "$GIT_DIR"/hooks/pre-commit
417 else
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800418 GIT_INDEX_FILE="$USE_INDEX" "$GIT_DIR"/hooks/pre-commit
Junio C Hamano130fcca2006-02-05 00:07:44 -0800419 fi || exit
420fi
Junio C Hamano0cfe1d32005-08-12 23:39:15 -0700421
Junio C Hamanoaba2da12005-08-25 18:57:35 -0700422if test "$log_message" != ''
423then
424 echo "$log_message"
425elif test "$logfile" != ""
426then
427 if test "$logfile" = -
428 then
429 test -t 0 &&
430 echo >&2 "(reading log message from standard input)"
431 cat
432 else
433 cat <"$logfile"
434 fi
435elif test "$use_commit" != ""
436then
437 git-cat-file commit "$use_commit" | sed -e '1,/^$/d'
Luben Tuikova9cb3c62006-10-12 14:52:42 -0700438elif test -f "$GIT_DIR/MERGE_MSG"
Junio C Hamanoe5215802005-11-01 22:01:28 -0800439then
440 cat "$GIT_DIR/MERGE_MSG"
Junio C Hamano7d0c6882006-06-23 01:37:02 -0700441elif test -f "$GIT_DIR/SQUASH_MSG"
442then
443 cat "$GIT_DIR/SQUASH_MSG"
Santi_Béjarf8e2c542005-10-09 17:30:19 -0700444fi | git-stripspace >"$GIT_DIR"/COMMIT_EDITMSG
Junio C Hamano2d569932005-08-31 17:15:25 -0700445
446case "$signoff" in
447t)
Junio C Hamanof6413392005-10-03 23:49:46 -0700448 {
449 echo
450 git-var GIT_COMMITTER_IDENT | sed -e '
451 s/>.*/>/
452 s/^/Signed-off-by: /
453 '
Santi_Béjarf8e2c542005-10-09 17:30:19 -0700454 } >>"$GIT_DIR"/COMMIT_EDITMSG
Junio C Hamano2d569932005-08-31 17:15:25 -0700455 ;;
456esac
457
Junio C Hamano475443c2006-04-12 11:45:18 -0700458if test -f "$GIT_DIR/MERGE_HEAD" && test -z "$no_edit"; then
Junio C Hamano2d569932005-08-31 17:15:25 -0700459 echo "#"
Alex Riesenb6ae5402006-01-05 12:44:59 +0100460 echo "# It looks like you may be committing a MERGE."
Junio C Hamano2d569932005-08-31 17:15:25 -0700461 echo "# If this is not correct, please remove the file"
462 echo "# $GIT_DIR/MERGE_HEAD"
463 echo "# and try again"
464 echo "#"
Santi_Béjarf8e2c542005-10-09 17:30:19 -0700465fi >>"$GIT_DIR"/COMMIT_EDITMSG
Junio C Hamanoaba2da12005-08-25 18:57:35 -0700466
Junio C Hamano130fcca2006-02-05 00:07:44 -0800467# Author
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800468if test '' != "$force_author"
469then
Mark Woodingf327dbc2006-04-13 22:01:24 +0000470 GIT_AUTHOR_NAME=`expr "z$force_author" : 'z\(.*[^ ]\) *<.*'` &&
471 GIT_AUTHOR_EMAIL=`expr "z$force_author" : '.*\(<.*\)'` &&
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800472 test '' != "$GIT_AUTHOR_NAME" &&
473 test '' != "$GIT_AUTHOR_EMAIL" ||
Pavel Roskin82e5a822006-07-10 01:50:18 -0400474 die "malformed --author parameter"
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800475 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
476elif test '' != "$use_commit"
Junio C Hamano130fcca2006-02-05 00:07:44 -0800477then
478 pick_author_script='
479 /^author /{
480 s/'\''/'\''\\'\'\''/g
481 h
482 s/^author \([^<]*\) <[^>]*> .*$/\1/
483 s/'\''/'\''\'\'\''/g
484 s/.*/GIT_AUTHOR_NAME='\''&'\''/p
485
486 g
487 s/^author [^<]* <\([^>]*\)> .*$/\1/
488 s/'\''/'\''\'\'\''/g
489 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
490
491 g
492 s/^author [^<]* <[^>]*> \(.*\)$/\1/
493 s/'\''/'\''\'\'\''/g
494 s/.*/GIT_AUTHOR_DATE='\''&'\''/p
495
496 q
497 }
498 '
499 set_author_env=`git-cat-file commit "$use_commit" |
500 LANG=C LC_ALL=C sed -ne "$pick_author_script"`
501 eval "$set_author_env"
502 export GIT_AUTHOR_NAME
503 export GIT_AUTHOR_EMAIL
504 export GIT_AUTHOR_DATE
Junio C Hamano130fcca2006-02-05 00:07:44 -0800505fi
506
Linus Torvalds96069cf2005-06-14 10:20:14 -0700507PARENTS="-p HEAD"
Junio C Hamano130fcca2006-02-05 00:07:44 -0800508if test -z "$initial_commit"
Junio C Hamano8098a172005-09-30 14:26:57 -0700509then
Shawn Pearcea3a733e2006-07-10 22:48:47 -0400510 rloga='commit'
Junio C Hamano5fec3ef2005-06-25 02:22:05 -0700511 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
Shawn Pearcea3a733e2006-07-10 22:48:47 -0400512 rloga='commit (merge)'
Junio C Hamano91063bb2005-09-08 13:47:12 -0700513 PARENTS="-p HEAD "`sed -e 's/^/-p /' "$GIT_DIR/MERGE_HEAD"`
Junio C Hamanob4019f02006-03-02 21:04:05 -0800514 elif test -n "$amend"; then
Shawn Pearcea3a733e2006-07-10 22:48:47 -0400515 rloga='commit (amend)'
Junio C Hamanob4019f02006-03-02 21:04:05 -0800516 PARENTS=$(git-cat-file commit HEAD |
517 sed -n -e '/^$/q' -e 's/^parent /-p /p')
Junio C Hamanoaba2da12005-08-25 18:57:35 -0700518 fi
Junio C Hamanocede7522006-09-27 02:06:31 -0700519 current="$(git-rev-parse --verify HEAD)"
Junio C Hamano8098a172005-09-30 14:26:57 -0700520else
521 if [ -z "$(git-ls-files)" ]; then
Shawn O. Pearceaeb80c72006-12-15 21:53:09 -0500522 echo >&2 'nothing to commit (use "git add file1 file2" to include for commit)'
Junio C Hamano8098a172005-09-30 14:26:57 -0700523 exit 1
524 fi
525 PARENTS=""
Shawn Pearcea3a733e2006-07-10 22:48:47 -0400526 rloga='commit (initial)'
Junio C Hamanocede7522006-09-27 02:06:31 -0700527 current=''
Linus Torvalds96069cf2005-06-14 10:20:14 -0700528fi
Junio C Hamano130fcca2006-02-05 00:07:44 -0800529
Junio C Hamano475443c2006-04-12 11:45:18 -0700530if test -z "$no_edit"
531then
532 {
Martin Waitz88a15312006-05-26 01:42:18 +0200533 echo ""
534 echo "# Please enter the commit message for your changes."
535 echo "# (Comment lines starting with '#' will not be included)"
Junio C Hamano475443c2006-04-12 11:45:18 -0700536 test -z "$only_include_assumed" || echo "$only_include_assumed"
537 run_status
538 } >>"$GIT_DIR"/COMMIT_EDITMSG
539else
540 # we need to check if there is anything to commit
541 run_status >/dev/null
542fi
Junio C Hamano85884522006-03-04 20:36:28 -0800543if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" -a -z "$amend" ]
Linus Torvaldsa3e870f2005-05-30 12:51:00 -0700544then
Junio C Hamano7d0c6882006-06-23 01:37:02 -0700545 rm -f "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG"
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800546 run_status
Linus Torvaldsa3e870f2005-05-30 12:51:00 -0700547 exit 1
548fi
Junio C Hamano475443c2006-04-12 11:45:18 -0700549
Junio C Hamano0c091292005-08-08 17:03:14 -0700550case "$no_edit" in
Junio C Hamano5fec3ef2005-06-25 02:22:05 -0700551'')
Junio C Hamano7334f062006-02-04 22:10:32 -0800552 case "${VISUAL:-$EDITOR},$TERM" in
553 ,dumb)
554 echo >&2 "Terminal is dumb but no VISUAL nor EDITOR defined."
555 echo >&2 "Please supply the commit log message using either"
556 echo >&2 "-m or -F option. A boilerplate log message has"
557 echo >&2 "been prepared in $GIT_DIR/COMMIT_EDITMSG"
Junio C Hamano130fcca2006-02-05 00:07:44 -0800558 exit 1
559 ;;
Junio C Hamano7334f062006-02-04 22:10:32 -0800560 esac
Seanec4e69c2006-05-13 23:09:32 -0400561 git-var GIT_AUTHOR_IDENT > /dev/null || die
562 git-var GIT_COMMITTER_IDENT > /dev/null || die
Santi_Béjarf8e2c542005-10-09 17:30:19 -0700563 ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR/COMMIT_EDITMSG"
Junio C Hamano5fec3ef2005-06-25 02:22:05 -0700564 ;;
565esac
Junio C Hamano89e2c5f2005-08-18 17:20:08 -0700566
567case "$verify" in
568t)
569 if test -x "$GIT_DIR"/hooks/commit-msg
570 then
Santi_Béjarf8e2c542005-10-09 17:30:19 -0700571 "$GIT_DIR"/hooks/commit-msg "$GIT_DIR"/COMMIT_EDITMSG || exit
Junio C Hamano89e2c5f2005-08-18 17:20:08 -0700572 fi
573esac
574
Yann Dirson29f4ad82006-06-24 00:04:05 +0200575if test -z "$no_edit"
576then
577 sed -e '
578 /^diff --git a\/.*/{
579 s///
580 q
581 }
582 /^#/d
583 ' "$GIT_DIR"/COMMIT_EDITMSG
584else
585 cat "$GIT_DIR"/COMMIT_EDITMSG
586fi |
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800587git-stripspace >"$GIT_DIR"/COMMIT_MSG
Santi_Béjarf8e2c542005-10-09 17:30:19 -0700588
589if cnt=`grep -v -i '^Signed-off-by' "$GIT_DIR"/COMMIT_MSG |
590 git-stripspace |
591 wc -l` &&
592 test 0 -lt $cnt
Junio C Hamano0c091292005-08-08 17:03:14 -0700593then
Junio C Hamano130fcca2006-02-05 00:07:44 -0800594 if test -z "$TMP_INDEX"
595 then
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800596 tree=$(GIT_INDEX_FILE="$USE_INDEX" git-write-tree)
Junio C Hamano130fcca2006-02-05 00:07:44 -0800597 else
598 tree=$(GIT_INDEX_FILE="$TMP_INDEX" git-write-tree) &&
599 rm -f "$TMP_INDEX"
600 fi &&
Santi_Béjarf8e2c542005-10-09 17:30:19 -0700601 commit=$(cat "$GIT_DIR"/COMMIT_MSG | git-commit-tree $tree $PARENTS) &&
Shawn Pearce67644a42006-05-19 05:16:18 -0400602 rlogm=$(sed -e 1q "$GIT_DIR"/COMMIT_MSG) &&
Junio C Hamanocede7522006-09-27 02:06:31 -0700603 git-update-ref -m "$rloga: $rlogm" HEAD $commit "$current" &&
Luben Tuikova9cb3c62006-10-12 14:52:42 -0700604 rm -f -- "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/MERGE_MSG" &&
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800605 if test -f "$NEXT_INDEX"
606 then
607 mv "$NEXT_INDEX" "$THIS_INDEX"
608 else
609 : ;# happy
610 fi
Junio C Hamano0c091292005-08-08 17:03:14 -0700611else
612 echo >&2 "* no commit message? aborting commit."
613 false
614fi
Linus Torvalds170241b2005-06-19 19:57:01 -0700615ret="$?"
Junio C Hamano7d0c6882006-06-23 01:37:02 -0700616rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG"
Junio C Hamano1536dd9c62006-02-11 18:55:43 -0800617if test -d "$GIT_DIR/rr-cache"
618then
619 git-rerere
620fi
Junio C Hamano89e2c5f2005-08-18 17:20:08 -0700621
Nicolas Pitreebd124c2006-12-14 23:15:44 -0500622if test "$ret" = 0
Junio C Hamano89e2c5f2005-08-18 17:20:08 -0700623then
Nicolas Pitreebd124c2006-12-14 23:15:44 -0500624 if test -x "$GIT_DIR"/hooks/post-commit
625 then
626 "$GIT_DIR"/hooks/post-commit
627 fi
628 if test -z "$quiet"
629 then
630 echo "Created${initial_commit:+ initial} commit $commit"
631 git-diff-tree --shortstat --summary --root --no-commit-id HEAD
632 fi
Junio C Hamano89e2c5f2005-08-18 17:20:08 -0700633fi
Junio C Hamano61f5cb72006-10-24 21:48:55 -0700634
Linus Torvalds170241b2005-06-19 19:57:01 -0700635exit "$ret"