blob: ab5e6bc1c8e594bdaba9d1950c18efa7c45d8852 [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
Junio C Hamano4170a192006-02-12 23:55:07 -08006USAGE='[-a] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit>] [-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
11branch=$(GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD)
12
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 Hamanocf7bb582006-02-10 00:45:59 -080032 cp "$THIS_INDEX" "$NEXT_INDEX"
33}
34
35report () {
36 header="#
37# $1:
38# ($2)
39#
40"
41 trailer=""
42 while read status name newname
43 do
44 printf '%s' "$header"
45 header=""
46 trailer="#
47"
48 case "$status" in
49 M ) echo "# modified: $name";;
50 D*) echo "# deleted: $name";;
51 T ) echo "# typechange: $name";;
52 C*) echo "# copied: $name -> $newname";;
53 R*) echo "# renamed: $name -> $newname";;
54 A*) echo "# new file: $name";;
55 U ) echo "# unmerged: $name";;
56 esac
57 done
58 printf '%s' "$trailer"
59 [ "$header" ]
Junio C Hamano5a798fb2006-02-05 16:08:01 -080060}
61
62run_status () {
Junio C Hamanocf7bb582006-02-10 00:45:59 -080063 (
64 # We always show status for the whole tree.
65 cd "$TOP"
66
67 # If TMP_INDEX is defined, that means we are doing
68 # "--only" partial commit, and that index file is used
69 # to build the tree for the commit. Otherwise, if
70 # NEXT_INDEX exists, that is the index file used to
71 # make the commit. Otherwise we are using as-is commit
72 # so the regular index file is what we use to compare.
73 if test '' != "$TMP_INDEX"
74 then
75 GIT_INDEX_FILE="$TMP_INDEX"
76 export GIT_INDEX_FILE
77 elif test -f "$NEXT_INDEX"
78 then
79 GIT_INDEX_FILE="$NEXT_INDEX"
80 export GIT_INDEX_FILE
81 fi
82
83 case "$branch" in
84 refs/heads/master) ;;
85 *) echo "# On branch $branch" ;;
86 esac
87
88 if test -z "$initial_commit"
89 then
Junio C Hamano9ae6be82006-02-10 18:38:24 -080090 git-diff-index -M --cached --name-status \
91 --diff-filter=MDTCRA HEAD |
92 sed -e '
93 s/\\/\\\\/g
94 s/ /\\ /g
95 ' |
96 report "Updated but not checked in" "will commit"
Junio C Hamanocf7bb582006-02-10 00:45:59 -080097 committable="$?"
98 else
99 echo '#
100# Initial commit
101#'
102 git-ls-files |
103 sed -e '
104 s/\\/\\\\/g
105 s/ /\\ /g
106 s/^/A /
107 ' |
108 report "Updated but not checked in" "will commit"
109
110 committable="$?"
111 fi
112
113 git-diff-files --name-status |
114 sed -e '
115 s/\\/\\\\/g
116 s/ /\\ /g
117 ' |
118 report "Changed but not updated" \
119 "use git-update-index to mark for commit"
120
121 if test -f "$GIT_DIR/info/exclude"
122 then
123 git-ls-files -z --others --directory \
124 --exclude-from="$GIT_DIR/info/exclude" \
125 --exclude-per-directory=.gitignore
126 else
127 git-ls-files -z --others --directory \
128 --exclude-per-directory=.gitignore
129 fi |
130 perl -e '$/ = "\0";
131 my $shown = 0;
132 while (<>) {
133 chomp;
134 s|\\|\\\\|g;
135 s|\t|\\t|g;
136 s|\n|\\n|g;
137 s/^/# /;
138 if (!$shown) {
139 print "#\n# Untracked files:\n";
140 print "# (use \"git add\" to add to commit)\n";
141 print "#\n";
142 $shown = 1;
143 }
144 print "$_\n";
145 }
146 '
Junio C Hamano9ae6be82006-02-10 18:38:24 -0800147
148 if test -n "$verbose"
149 then
150 git-diff-index --cached -M -p --diff-filter=MDTCRA HEAD
151 fi
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800152 case "$committable" in
153 0)
154 echo "nothing to commit"
155 exit 1
156 esac
157 exit 0
158 )
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800159}
160
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800161trap '
162 test -z "$TMP_INDEX" || {
163 test -f "$TMP_INDEX" && rm -f "$TMP_INDEX"
164 }
165 rm -f "$NEXT_INDEX"
166' 0
167
168################################################################
169# Command line argument parsing and sanity checking
170
Junio C Hamano130fcca2006-02-05 00:07:44 -0800171all=
172also=
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800173only=
Junio C Hamano130fcca2006-02-05 00:07:44 -0800174logfile=
175use_commit=
176no_edit=
177log_given=
178log_message=
179verify=t
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800180verbose=
Junio C Hamano130fcca2006-02-05 00:07:44 -0800181signoff=
182force_author=
Junio C Hamano0c091292005-08-08 17:03:14 -0700183while case "$#" in 0) break;; esac
Junio C Hamano5fec3ef2005-06-25 02:22:05 -0700184do
Junio C Hamano0c091292005-08-08 17:03:14 -0700185 case "$1" in
Junio C Hamano130fcca2006-02-05 00:07:44 -0800186 -F|--F|-f|--f|--fi|--fil|--file)
187 case "$#" in 1) usage ;; esac
188 shift
189 no_edit=t
190 log_given=t$log_given
191 logfile="$1"
192 shift
193 ;;
194 -F*|-f*)
195 no_edit=t
196 log_given=t$log_given
197 logfile=`expr "$1" : '-[Ff]\(.*\)'`
198 shift
199 ;;
200 --F=*|--f=*|--fi=*|--fil=*|--file=*)
201 no_edit=t
202 log_given=t$log_given
203 logfile=`expr "$1" : '-[^=]*=\(.*\)'`
204 shift
205 ;;
Junio C Hamano0c091292005-08-08 17:03:14 -0700206 -a|--a|--al|--all)
Junio C Hamano130fcca2006-02-05 00:07:44 -0800207 all=t
208 shift
209 ;;
210 --au=*|--aut=*|--auth=*|--autho=*|--author=*)
211 force_author=`expr "$1" : '-[^=]*=\(.*\)'`
212 shift
213 ;;
214 --au|--aut|--auth|--autho|--author)
215 case "$#" in 1) usage ;; esac
216 shift
217 force_author="$1"
218 shift
219 ;;
220 -e|--e|--ed|--edi|--edit)
221 no_edit=
222 shift
223 ;;
224 -i|--i|--in|--inc|--incl|--inclu|--includ|--include)
225 also=t
226 shift
227 ;;
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800228 -o|--o|--on|--onl|--only)
229 only=t
230 shift
231 ;;
Junio C Hamano0c091292005-08-08 17:03:14 -0700232 -m|--m|--me|--mes|--mess|--messa|--messag|--message)
Junio C Hamano130fcca2006-02-05 00:07:44 -0800233 case "$#" in 1) usage ;; esac
234 shift
235 log_given=t$log_given
236 log_message="$1"
237 no_edit=t
238 shift
239 ;;
240 -m*)
241 log_given=t$log_given
242 log_message=`expr "$1" : '-m\(.*\)'`
243 no_edit=t
244 shift
245 ;;
246 --m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*)
247 log_given=t$log_given
248 log_message=`expr "$1" : '-[^=]*=\(.*\)'`
249 no_edit=t
250 shift
251 ;;
252 -n|--n|--no|--no-|--no-v|--no-ve|--no-ver|--no-veri|--no-verif|--no-verify)
253 verify=
254 shift
255 ;;
256 -c)
257 case "$#" in 1) usage ;; esac
258 shift
259 log_given=t$log_given
260 use_commit="$1"
261 no_edit=
262 shift
263 ;;
264 --ree=*|--reed=*|--reedi=*|--reedit=*|--reedit-=*|--reedit-m=*|\
Junio C Hamano0c091292005-08-08 17:03:14 -0700265 --reedit-me=*|--reedit-mes=*|--reedit-mess=*|--reedit-messa=*|\
266 --reedit-messag=*|--reedit-message=*)
Junio C Hamano130fcca2006-02-05 00:07:44 -0800267 log_given=t$log_given
268 use_commit=`expr "$1" : '-[^=]*=\(.*\)'`
269 no_edit=
270 shift
271 ;;
272 --ree|--reed|--reedi|--reedit|--reedit-|--reedit-m|--reedit-me|\
Junio C Hamano0c091292005-08-08 17:03:14 -0700273 --reedit-mes|--reedit-mess|--reedit-messa|--reedit-messag|--reedit-message)
Junio C Hamano130fcca2006-02-05 00:07:44 -0800274 case "$#" in 1) usage ;; esac
275 shift
276 log_given=t$log_given
277 use_commit="$1"
278 no_edit=
279 shift
280 ;;
281 -C)
282 case "$#" in 1) usage ;; esac
283 shift
284 log_given=t$log_given
285 use_commit="$1"
286 no_edit=t
287 shift
288 ;;
289 --reu=*|--reus=*|--reuse=*|--reuse-=*|--reuse-m=*|--reuse-me=*|\
Junio C Hamano0c091292005-08-08 17:03:14 -0700290 --reuse-mes=*|--reuse-mess=*|--reuse-messa=*|--reuse-messag=*|\
291 --reuse-message=*)
Junio C Hamano130fcca2006-02-05 00:07:44 -0800292 log_given=t$log_given
293 use_commit=`expr "$1" : '-[^=]*=\(.*\)'`
294 no_edit=t
295 shift
296 ;;
297 --reu|--reus|--reuse|--reuse-|--reuse-m|--reuse-me|--reuse-mes|\
Junio C Hamano0c091292005-08-08 17:03:14 -0700298 --reuse-mess|--reuse-messa|--reuse-messag|--reuse-message)
Junio C Hamano130fcca2006-02-05 00:07:44 -0800299 case "$#" in 1) usage ;; esac
300 shift
301 log_given=t$log_given
302 use_commit="$1"
303 no_edit=t
304 shift
305 ;;
Junio C Hamano0cfe1d32005-08-12 23:39:15 -0700306 -s|--s|--si|--sig|--sign|--signo|--signof|--signoff)
Junio C Hamano130fcca2006-02-05 00:07:44 -0800307 signoff=t
308 shift
309 ;;
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800310 -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
311 verbose=t
312 shift
Junio C Hamano130fcca2006-02-05 00:07:44 -0800313 ;;
Junio C Hamano0c091292005-08-08 17:03:14 -0700314 --)
Junio C Hamano130fcca2006-02-05 00:07:44 -0800315 shift
316 break
317 ;;
Junio C Hamano0c091292005-08-08 17:03:14 -0700318 -*)
Junio C Hamano130fcca2006-02-05 00:07:44 -0800319 usage
320 ;;
Junio C Hamano0c091292005-08-08 17:03:14 -0700321 *)
Junio C Hamano130fcca2006-02-05 00:07:44 -0800322 break
323 ;;
Junio C Hamano0c091292005-08-08 17:03:14 -0700324 esac
Junio C Hamano5fec3ef2005-06-25 02:22:05 -0700325done
326
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800327################################################################
328# Sanity check options
329
Junio C Hamano0c091292005-08-08 17:03:14 -0700330case "$log_given" in
331tt*)
332 die "Only one of -c/-C/-F/-m can be used." ;;
333esac
334
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800335case "$#,$also$only" in
336*,tt)
337 die "Only one of --include/--only can be used." ;;
3380,t)
339 die "No paths with --include/--only does not make sense." ;;
3400,)
341 ;;
342*,)
Junio C Hamano4170a192006-02-12 23:55:07 -0800343 echo >&2 "assuming --only paths..."
344 also=
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800345
346 # If we are going to launch an editor, the message won't be
347 # shown without this...
348 test -z "$log_given$status_only" && sleep 1
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800349 ;;
350esac
351unset only
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800352case "$all,$also,$#" in
353t,t,*)
354 die "Cannot use -a and -i at the same time." ;;
355t,,[1-9]*)
356 die "Paths with -a does not make sense." ;;
357,t,0)
358 die "No paths with -i does not make sense." ;;
359esac
360
361################################################################
362# Prepare index to have a tree to be committed
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800363
Junio C Hamano130fcca2006-02-05 00:07:44 -0800364TOP=`git-rev-parse --show-cdup`
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800365if test -z "$TOP"
366then
367 TOP=./
368fi
Junio C Hamano130fcca2006-02-05 00:07:44 -0800369
370case "$all,$also" in
Junio C Hamano130fcca2006-02-05 00:07:44 -0800371t,)
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800372 save_index &&
Junio C Hamano130fcca2006-02-05 00:07:44 -0800373 (
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800374 cd "$TOP"
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800375 GIT_INDEX_FILE="$NEXT_INDEX"
376 export GIT_INDEX_FILE
Junio C Hamano130fcca2006-02-05 00:07:44 -0800377 git-diff-files --name-only -z |
378 git-update-index --remove -z --stdin
379 )
380 ;;
381,t)
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800382 save_index &&
Junio C Hamano130fcca2006-02-05 00:07:44 -0800383 git-diff-files --name-only -z -- "$@" |
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800384 (
385 cd "$TOP"
386 GIT_INDEX_FILE="$NEXT_INDEX"
387 export GIT_INDEX_FILE
388 git-update-index --remove -z --stdin
389 )
Junio C Hamano22cff6a2005-08-16 18:08:19 -0700390 ;;
Junio C Hamano130fcca2006-02-05 00:07:44 -0800391,)
392 case "$#" in
393 0)
394 ;; # commit as-is
395 *)
396 if test -f "$GIT_DIR/MERGE_HEAD"
397 then
398 refuse_partial "Cannot do a partial commit during a merge."
399 fi
400 TMP_INDEX="$GIT_DIR/tmp-index$$"
401 if test -z "$initial_commit"
402 then
403 # make sure index is clean at the specified paths, or
404 # they are additions.
405 dirty_in_index=`git-diff-index --cached --name-status \
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800406 --diff-filter=DMTU HEAD -- "$@"`
Junio C Hamano130fcca2006-02-05 00:07:44 -0800407 test -z "$dirty_in_index" ||
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800408 refuse_partial "Different in index and the last commit:
Junio C Hamano130fcca2006-02-05 00:07:44 -0800409$dirty_in_index"
410 fi
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800411 commit_only=`git-ls-files -- "$@"`
412
413 # Build the temporary index and update the real index
414 # the same way.
415 if test -z "$initial_commit"
416 then
417 cp "$THIS_INDEX" "$TMP_INDEX"
418 GIT_INDEX_FILE="$TMP_INDEX" git-read-tree -m HEAD
419 else
420 rm -f "$TMP_INDEX"
421 fi || exit
422
423 echo "$commit_only" |
424 GIT_INDEX_FILE="$TMP_INDEX" \
425 git-update-index --add --remove --stdin &&
426
427 save_index &&
428 echo "$commit_only" |
429 (
430 GIT_INDEX_FILE="$NEXT_INDEX"
431 export GIT_INDEX_FILE
432 git-update-index --remove --stdin
433 ) || exit
434 ;;
Junio C Hamano130fcca2006-02-05 00:07:44 -0800435 esac
Junio C Hamanof678dd12005-11-25 13:33:14 -0800436 ;;
Junio C Hamano130fcca2006-02-05 00:07:44 -0800437esac
438
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800439################################################################
440# If we do as-is commit, the index file will be THIS_INDEX,
441# otherwise NEXT_INDEX after we make this commit. We leave
442# the index as is if we abort.
Junio C Hamano0c091292005-08-08 17:03:14 -0700443
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800444if test -f "$NEXT_INDEX"
Junio C Hamano130fcca2006-02-05 00:07:44 -0800445then
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800446 USE_INDEX="$NEXT_INDEX"
447else
448 USE_INDEX="$THIS_INDEX"
Junio C Hamano130fcca2006-02-05 00:07:44 -0800449fi
450
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800451GIT_INDEX_FILE="$USE_INDEX" \
452 git-update-index -q $unmerged_ok_if_status --refresh || exit
453
454################################################################
455# If the request is status, just show it and exit.
456
457case "$0" in
458*status)
459 run_status
460 exit $?
461esac
462
463################################################################
464# Grab commit message, write out tree and make commit.
465
Junio C Hamano130fcca2006-02-05 00:07:44 -0800466if test t = "$verify" && test -x "$GIT_DIR"/hooks/pre-commit
467then
468 if test "$TMP_INDEX"
469 then
470 GIT_INDEX_FILE="$TMP_INDEX" "$GIT_DIR"/hooks/pre-commit
471 else
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800472 GIT_INDEX_FILE="$USE_INDEX" "$GIT_DIR"/hooks/pre-commit
Junio C Hamano130fcca2006-02-05 00:07:44 -0800473 fi || exit
474fi
Junio C Hamano0cfe1d32005-08-12 23:39:15 -0700475
Junio C Hamanoaba2da12005-08-25 18:57:35 -0700476if test "$log_message" != ''
477then
478 echo "$log_message"
479elif test "$logfile" != ""
480then
481 if test "$logfile" = -
482 then
483 test -t 0 &&
484 echo >&2 "(reading log message from standard input)"
485 cat
486 else
487 cat <"$logfile"
488 fi
489elif test "$use_commit" != ""
490then
491 git-cat-file commit "$use_commit" | sed -e '1,/^$/d'
Junio C Hamanoe5215802005-11-01 22:01:28 -0800492elif test -f "$GIT_DIR/MERGE_HEAD" && test -f "$GIT_DIR/MERGE_MSG"
493then
494 cat "$GIT_DIR/MERGE_MSG"
Santi_Béjarf8e2c542005-10-09 17:30:19 -0700495fi | git-stripspace >"$GIT_DIR"/COMMIT_EDITMSG
Junio C Hamano2d569932005-08-31 17:15:25 -0700496
497case "$signoff" in
498t)
Junio C Hamanof6413392005-10-03 23:49:46 -0700499 {
500 echo
501 git-var GIT_COMMITTER_IDENT | sed -e '
502 s/>.*/>/
503 s/^/Signed-off-by: /
504 '
Santi_Béjarf8e2c542005-10-09 17:30:19 -0700505 } >>"$GIT_DIR"/COMMIT_EDITMSG
Junio C Hamano2d569932005-08-31 17:15:25 -0700506 ;;
507esac
508
509if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
510 echo "#"
Alex Riesenb6ae5402006-01-05 12:44:59 +0100511 echo "# It looks like you may be committing a MERGE."
Junio C Hamano2d569932005-08-31 17:15:25 -0700512 echo "# If this is not correct, please remove the file"
513 echo "# $GIT_DIR/MERGE_HEAD"
514 echo "# and try again"
515 echo "#"
Santi_Béjarf8e2c542005-10-09 17:30:19 -0700516fi >>"$GIT_DIR"/COMMIT_EDITMSG
Junio C Hamanoaba2da12005-08-25 18:57:35 -0700517
Junio C Hamano130fcca2006-02-05 00:07:44 -0800518# Author
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800519if test '' != "$force_author"
520then
521 GIT_AUTHOR_NAME=`expr "$force_author" : '\(.*[^ ]\) *<.*'` &&
522 GIT_AUTHOR_EMAIL=`expr "$force_author" : '.*\(<.*\)'` &&
523 test '' != "$GIT_AUTHOR_NAME" &&
524 test '' != "$GIT_AUTHOR_EMAIL" ||
525 die "malformatted --author parameter"
526 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
527elif test '' != "$use_commit"
Junio C Hamano130fcca2006-02-05 00:07:44 -0800528then
529 pick_author_script='
530 /^author /{
531 s/'\''/'\''\\'\'\''/g
532 h
533 s/^author \([^<]*\) <[^>]*> .*$/\1/
534 s/'\''/'\''\'\'\''/g
535 s/.*/GIT_AUTHOR_NAME='\''&'\''/p
536
537 g
538 s/^author [^<]* <\([^>]*\)> .*$/\1/
539 s/'\''/'\''\'\'\''/g
540 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
541
542 g
543 s/^author [^<]* <[^>]*> \(.*\)$/\1/
544 s/'\''/'\''\'\'\''/g
545 s/.*/GIT_AUTHOR_DATE='\''&'\''/p
546
547 q
548 }
549 '
550 set_author_env=`git-cat-file commit "$use_commit" |
551 LANG=C LC_ALL=C sed -ne "$pick_author_script"`
552 eval "$set_author_env"
553 export GIT_AUTHOR_NAME
554 export GIT_AUTHOR_EMAIL
555 export GIT_AUTHOR_DATE
Junio C Hamano130fcca2006-02-05 00:07:44 -0800556fi
557
Linus Torvalds96069cf2005-06-14 10:20:14 -0700558PARENTS="-p HEAD"
Junio C Hamano130fcca2006-02-05 00:07:44 -0800559if test -z "$initial_commit"
Junio C Hamano8098a172005-09-30 14:26:57 -0700560then
Junio C Hamano5fec3ef2005-06-25 02:22:05 -0700561 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
Junio C Hamano91063bb2005-09-08 13:47:12 -0700562 PARENTS="-p HEAD "`sed -e 's/^/-p /' "$GIT_DIR/MERGE_HEAD"`
Junio C Hamanoaba2da12005-08-25 18:57:35 -0700563 fi
Junio C Hamano8098a172005-09-30 14:26:57 -0700564else
565 if [ -z "$(git-ls-files)" ]; then
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800566 echo >&2 Nothing to commit
Junio C Hamano8098a172005-09-30 14:26:57 -0700567 exit 1
568 fi
569 PARENTS=""
Linus Torvalds96069cf2005-06-14 10:20:14 -0700570fi
Junio C Hamano130fcca2006-02-05 00:07:44 -0800571
Junio C Hamano9ae6be82006-02-10 18:38:24 -0800572run_status >>"$GIT_DIR"/COMMIT_EDITMSG
Santi_Béjardf342972005-10-05 18:58:10 +0200573if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" ]
Linus Torvaldsa3e870f2005-05-30 12:51:00 -0700574then
Santi_Béjarf8e2c542005-10-09 17:30:19 -0700575 rm -f "$GIT_DIR/COMMIT_EDITMSG"
Junio C Hamano5a798fb2006-02-05 16:08:01 -0800576 run_status
Linus Torvaldsa3e870f2005-05-30 12:51:00 -0700577 exit 1
578fi
Junio C Hamano0c091292005-08-08 17:03:14 -0700579case "$no_edit" in
Junio C Hamano5fec3ef2005-06-25 02:22:05 -0700580'')
Junio C Hamano7334f062006-02-04 22:10:32 -0800581 case "${VISUAL:-$EDITOR},$TERM" in
582 ,dumb)
583 echo >&2 "Terminal is dumb but no VISUAL nor EDITOR defined."
584 echo >&2 "Please supply the commit log message using either"
585 echo >&2 "-m or -F option. A boilerplate log message has"
586 echo >&2 "been prepared in $GIT_DIR/COMMIT_EDITMSG"
Junio C Hamano130fcca2006-02-05 00:07:44 -0800587 exit 1
588 ;;
Junio C Hamano7334f062006-02-04 22:10:32 -0800589 esac
Santi_Béjarf8e2c542005-10-09 17:30:19 -0700590 ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR/COMMIT_EDITMSG"
Junio C Hamano5fec3ef2005-06-25 02:22:05 -0700591 ;;
592esac
Junio C Hamano89e2c5f2005-08-18 17:20:08 -0700593
594case "$verify" in
595t)
596 if test -x "$GIT_DIR"/hooks/commit-msg
597 then
Santi_Béjarf8e2c542005-10-09 17:30:19 -0700598 "$GIT_DIR"/hooks/commit-msg "$GIT_DIR"/COMMIT_EDITMSG || exit
Junio C Hamano89e2c5f2005-08-18 17:20:08 -0700599 fi
600esac
601
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800602sed -e '
Junio C Hamano9ae6be82006-02-10 18:38:24 -0800603 /^diff --git a\/.*/{
604 s///
605 q
606 }
607 /^#/d
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800608' "$GIT_DIR"/COMMIT_EDITMSG |
609git-stripspace >"$GIT_DIR"/COMMIT_MSG
Santi_Béjarf8e2c542005-10-09 17:30:19 -0700610
611if cnt=`grep -v -i '^Signed-off-by' "$GIT_DIR"/COMMIT_MSG |
612 git-stripspace |
613 wc -l` &&
614 test 0 -lt $cnt
Junio C Hamano0c091292005-08-08 17:03:14 -0700615then
Junio C Hamano130fcca2006-02-05 00:07:44 -0800616 if test -z "$TMP_INDEX"
617 then
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800618 tree=$(GIT_INDEX_FILE="$USE_INDEX" git-write-tree)
Junio C Hamano130fcca2006-02-05 00:07:44 -0800619 else
620 tree=$(GIT_INDEX_FILE="$TMP_INDEX" git-write-tree) &&
621 rm -f "$TMP_INDEX"
622 fi &&
Santi_Béjarf8e2c542005-10-09 17:30:19 -0700623 commit=$(cat "$GIT_DIR"/COMMIT_MSG | git-commit-tree $tree $PARENTS) &&
Junio C Hamanobf7960e2005-09-27 18:14:27 -0700624 git-update-ref HEAD $commit $current &&
Junio C Hamanocf7bb582006-02-10 00:45:59 -0800625 rm -f -- "$GIT_DIR/MERGE_HEAD" &&
626 if test -f "$NEXT_INDEX"
627 then
628 mv "$NEXT_INDEX" "$THIS_INDEX"
629 else
630 : ;# happy
631 fi
Junio C Hamano0c091292005-08-08 17:03:14 -0700632else
633 echo >&2 "* no commit message? aborting commit."
634 false
635fi
Linus Torvalds170241b2005-06-19 19:57:01 -0700636ret="$?"
Santi_Béjarf8e2c542005-10-09 17:30:19 -0700637rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG"
Junio C Hamano1536dd9c62006-02-11 18:55:43 -0800638if test -d "$GIT_DIR/rr-cache"
639then
640 git-rerere
641fi
Junio C Hamano89e2c5f2005-08-18 17:20:08 -0700642
643if test -x "$GIT_DIR"/hooks/post-commit && test "$ret" = 0
644then
645 "$GIT_DIR"/hooks/post-commit
646fi
Linus Torvalds170241b2005-06-19 19:57:01 -0700647exit "$ret"