]>
Commit | Line | Data |
---|---|---|
a3e870f2 | 1 | #!/bin/sh |
5fec3ef1 JH |
2 | # |
3 | # Copyright (c) 2005 Linus Torvalds | |
130fcca6 JH |
4 | # Copyright (c) 2006 Junio C Hamano |
5 | ||
d1cc130a | 6 | USAGE='[-a | --interactive] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit> | --amend] [-u] [-e] [--author <author>] [--template <file>] [[-i | -o] <path>...]' |
130fcca6 | 7 | SUBDIRECTORY_OK=Yes |
ae2b0f15 | 8 | . git-sh-setup |
7eff28a9 | 9 | require_work_tree |
b33e9666 | 10 | |
5be60078 | 11 | git rev-parse --verify HEAD >/dev/null 2>&1 || initial_commit=t |
cf7bb589 JH |
12 | |
13 | case "$0" in | |
14 | *status) | |
15 | status_only=t | |
2b5f9a8c | 16 | ;; |
cf7bb589 JH |
17 | *commit) |
18 | status_only= | |
2b5f9a8c | 19 | ;; |
cf7bb589 | 20 | esac |
130fcca6 JH |
21 | |
22 | refuse_partial () { | |
23 | echo >&2 "$1" | |
130fcca6 JH |
24 | echo >&2 "You might have meant to say 'git commit -i paths...', perhaps?" |
25 | exit 1 | |
26 | } | |
27 | ||
cf7bb589 JH |
28 | THIS_INDEX="$GIT_DIR/index" |
29 | NEXT_INDEX="$GIT_DIR/next-index$$" | |
30 | rm -f "$NEXT_INDEX" | |
5a798fb5 | 31 | save_index () { |
cc7d5bcf | 32 | cp -p "$THIS_INDEX" "$NEXT_INDEX" |
cf7bb589 JH |
33 | } |
34 | ||
5a798fb5 | 35 | run_status () { |
cf7bb589 JH |
36 | # 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 | |
3de63c3f MW |
44 | GIT_INDEX_FILE="$TMP_INDEX" |
45 | export GIT_INDEX_FILE | |
cf7bb589 JH |
46 | elif test -f "$NEXT_INDEX" |
47 | then | |
3de63c3f MW |
48 | GIT_INDEX_FILE="$NEXT_INDEX" |
49 | export GIT_INDEX_FILE | |
cf7bb589 JH |
50 | fi |
51 | ||
09b0d9dd BH |
52 | if test "$status_only" = "t" -o "$use_status_color" = "t"; then |
53 | color= | |
54 | else | |
55 | color=--nocolor | |
56 | fi | |
5be60078 | 57 | git runstatus ${color} \ |
3de63c3f MW |
58 | ${verbose:+--verbose} \ |
59 | ${amend:+--amend} \ | |
2074cb0a | 60 | ${untracked_files:+--untracked} |
5a798fb5 JH |
61 | } |
62 | ||
cf7bb589 JH |
63 | trap ' |
64 | test -z "$TMP_INDEX" || { | |
65 | test -f "$TMP_INDEX" && rm -f "$TMP_INDEX" | |
66 | } | |
67 | rm -f "$NEXT_INDEX" | |
68 | ' 0 | |
69 | ||
70 | ################################################################ | |
71 | # Command line argument parsing and sanity checking | |
72 | ||
130fcca6 JH |
73 | all= |
74 | also= | |
6cbf07ef | 75 | interactive= |
5a798fb5 | 76 | only= |
130fcca6 JH |
77 | logfile= |
78 | use_commit= | |
b4019f04 | 79 | amend= |
cda8ab59 | 80 | edit_flag= |
130fcca6 JH |
81 | no_edit= |
82 | log_given= | |
83 | log_message= | |
84 | verify=t | |
ebd124c6 | 85 | quiet= |
cf7bb589 | 86 | verbose= |
130fcca6 JH |
87 | signoff= |
88 | force_author= | |
bba319b5 | 89 | only_include_assumed= |
443f8338 | 90 | untracked_files= |
d1cc130a | 91 | templatefile="`git config commit.template`" |
0c091296 | 92 | while case "$#" in 0) break;; esac |
5fec3ef1 | 93 | do |
3de63c3f MW |
94 | case "$1" in |
95 | -F|--F|-f|--f|--fi|--fil|--file) | |
96 | case "$#" in 1) usage ;; esac | |
97 | shift | |
98 | no_edit=t | |
99 | log_given=t$log_given | |
100 | logfile="$1" | |
101 | shift | |
102 | ;; | |
103 | -F*|-f*) | |
104 | no_edit=t | |
105 | log_given=t$log_given | |
106 | logfile=`expr "z$1" : 'z-[Ff]\(.*\)'` | |
107 | shift | |
108 | ;; | |
109 | --F=*|--f=*|--fi=*|--fil=*|--file=*) | |
110 | no_edit=t | |
111 | log_given=t$log_given | |
112 | logfile=`expr "z$1" : 'z-[^=]*=\(.*\)'` | |
113 | shift | |
114 | ;; | |
115 | -a|--a|--al|--all) | |
116 | all=t | |
117 | shift | |
118 | ;; | |
119 | --au=*|--aut=*|--auth=*|--autho=*|--author=*) | |
120 | force_author=`expr "z$1" : 'z-[^=]*=\(.*\)'` | |
121 | shift | |
122 | ;; | |
123 | --au|--aut|--auth|--autho|--author) | |
124 | case "$#" in 1) usage ;; esac | |
125 | shift | |
126 | force_author="$1" | |
127 | shift | |
128 | ;; | |
129 | -e|--e|--ed|--edi|--edit) | |
130 | edit_flag=t | |
131 | shift | |
132 | ;; | |
133 | -i|--i|--in|--inc|--incl|--inclu|--includ|--include) | |
134 | also=t | |
135 | shift | |
136 | ;; | |
6cbf07ef PB |
137 | --int|--inte|--inter|--intera|--interac|--interact|--interacti|\ |
138 | --interactiv|--interactive) | |
139 | interactive=t | |
140 | shift | |
141 | ;; | |
3de63c3f MW |
142 | -o|--o|--on|--onl|--only) |
143 | only=t | |
144 | shift | |
145 | ;; | |
146 | -m|--m|--me|--mes|--mess|--messa|--messag|--message) | |
147 | case "$#" in 1) usage ;; esac | |
148 | shift | |
149 | log_given=m$log_given | |
150 | if test "$log_message" = '' | |
151 | then | |
152 | log_message="$1" | |
153 | else | |
154 | log_message="$log_message | |
6891281c SP |
155 | |
156 | $1" | |
3de63c3f MW |
157 | fi |
158 | no_edit=t | |
159 | shift | |
160 | ;; | |
161 | -m*) | |
162 | log_given=m$log_given | |
163 | if test "$log_message" = '' | |
164 | then | |
165 | log_message=`expr "z$1" : 'z-m\(.*\)'` | |
166 | else | |
167 | log_message="$log_message | |
6891281c | 168 | |
8096fae7 | 169 | `expr "z$1" : 'z-m\(.*\)'`" |
3de63c3f MW |
170 | fi |
171 | no_edit=t | |
172 | shift | |
173 | ;; | |
174 | --m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*) | |
175 | log_given=m$log_given | |
176 | if test "$log_message" = '' | |
177 | then | |
178 | log_message=`expr "z$1" : 'z-[^=]*=\(.*\)'` | |
179 | else | |
180 | log_message="$log_message | |
6891281c | 181 | |
8096fae7 | 182 | `expr "z$1" : 'zq-[^=]*=\(.*\)'`" |
3de63c3f MW |
183 | fi |
184 | no_edit=t | |
185 | shift | |
186 | ;; | |
187 | -n|--n|--no|--no-|--no-v|--no-ve|--no-ver|--no-veri|--no-verif|\ | |
188 | --no-verify) | |
189 | verify= | |
190 | shift | |
191 | ;; | |
192 | --a|--am|--ame|--amen|--amend) | |
193 | amend=t | |
3de63c3f MW |
194 | use_commit=HEAD |
195 | shift | |
196 | ;; | |
197 | -c) | |
198 | case "$#" in 1) usage ;; esac | |
199 | shift | |
200 | log_given=t$log_given | |
201 | use_commit="$1" | |
202 | no_edit= | |
203 | shift | |
204 | ;; | |
205 | --ree=*|--reed=*|--reedi=*|--reedit=*|--reedit-=*|--reedit-m=*|\ | |
206 | --reedit-me=*|--reedit-mes=*|--reedit-mess=*|--reedit-messa=*|\ | |
207 | --reedit-messag=*|--reedit-message=*) | |
208 | log_given=t$log_given | |
209 | use_commit=`expr "z$1" : 'z-[^=]*=\(.*\)'` | |
210 | no_edit= | |
211 | shift | |
212 | ;; | |
213 | --ree|--reed|--reedi|--reedit|--reedit-|--reedit-m|--reedit-me|\ | |
214 | --reedit-mes|--reedit-mess|--reedit-messa|--reedit-messag|\ | |
215 | --reedit-message) | |
216 | case "$#" in 1) usage ;; esac | |
217 | shift | |
218 | log_given=t$log_given | |
219 | use_commit="$1" | |
220 | no_edit= | |
221 | shift | |
222 | ;; | |
223 | -C) | |
224 | case "$#" in 1) usage ;; esac | |
225 | shift | |
226 | log_given=t$log_given | |
227 | use_commit="$1" | |
228 | no_edit=t | |
229 | shift | |
230 | ;; | |
231 | --reu=*|--reus=*|--reuse=*|--reuse-=*|--reuse-m=*|--reuse-me=*|\ | |
232 | --reuse-mes=*|--reuse-mess=*|--reuse-messa=*|--reuse-messag=*|\ | |
233 | --reuse-message=*) | |
234 | log_given=t$log_given | |
235 | use_commit=`expr "z$1" : 'z-[^=]*=\(.*\)'` | |
236 | no_edit=t | |
237 | shift | |
238 | ;; | |
239 | --reu|--reus|--reuse|--reuse-|--reuse-m|--reuse-me|--reuse-mes|\ | |
240 | --reuse-mess|--reuse-messa|--reuse-messag|--reuse-message) | |
241 | case "$#" in 1) usage ;; esac | |
242 | shift | |
243 | log_given=t$log_given | |
244 | use_commit="$1" | |
245 | no_edit=t | |
246 | shift | |
247 | ;; | |
248 | -s|--s|--si|--sig|--sign|--signo|--signof|--signoff) | |
249 | signoff=t | |
250 | shift | |
251 | ;; | |
d1cc130a SG |
252 | -t|--t|--te|--tem|--temp|--templ|--templa|--templat|--template) |
253 | case "$#" in 1) usage ;; esac | |
254 | shift | |
255 | templatefile="$1" | |
256 | no_edit= | |
257 | shift | |
258 | ;; | |
ebd124c6 NP |
259 | -q|--q|--qu|--qui|--quie|--quiet) |
260 | quiet=t | |
261 | shift | |
262 | ;; | |
3de63c3f MW |
263 | -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose) |
264 | verbose=t | |
265 | shift | |
266 | ;; | |
267 | -u|--u|--un|--unt|--untr|--untra|--untrac|--untrack|--untracke|\ | |
268 | --untracked|--untracked-|--untracked-f|--untracked-fi|--untracked-fil|\ | |
269 | --untracked-file|--untracked-files) | |
270 | untracked_files=t | |
271 | shift | |
272 | ;; | |
273 | --) | |
274 | shift | |
275 | break | |
276 | ;; | |
277 | -*) | |
278 | usage | |
279 | ;; | |
280 | *) | |
281 | break | |
282 | ;; | |
283 | esac | |
5fec3ef1 | 284 | done |
cda8ab59 | 285 | case "$edit_flag" in t) no_edit= ;; esac |
5fec3ef1 | 286 | |
cf7bb589 JH |
287 | ################################################################ |
288 | # Sanity check options | |
289 | ||
b4019f04 JH |
290 | case "$amend,$initial_commit" in |
291 | t,t) | |
3de63c3f | 292 | die "You do not have anything to amend." ;; |
b4019f04 | 293 | t,) |
3de63c3f MW |
294 | if [ -f "$GIT_DIR/MERGE_HEAD" ]; then |
295 | die "You are in the middle of a merge -- cannot amend." | |
296 | fi ;; | |
b4019f04 JH |
297 | esac |
298 | ||
0c091296 JH |
299 | case "$log_given" in |
300 | tt*) | |
6d4bbebd | 301 | die "Only one of -c/-C/-F can be used." ;; |
6891281c | 302 | *tm*|*mt*) |
6d4bbebd | 303 | die "Option -m cannot be combined with -c/-C/-F." ;; |
0c091296 JH |
304 | esac |
305 | ||
6a74642c JH |
306 | case "$#,$also,$only,$amend" in |
307 | *,t,t,*) | |
3de63c3f | 308 | die "Only one of --include/--only can be used." ;; |
6a74642c | 309 | 0,t,,* | 0,,t,) |
3de63c3f | 310 | die "No paths with --include/--only does not make sense." ;; |
6a74642c | 311 | 0,,t,t) |
3de63c3f | 312 | only_include_assumed="# Clever... amending the last one with dirty index." ;; |
6a74642c | 313 | 0,,,*) |
3de63c3f | 314 | ;; |
6a74642c | 315 | *,,,*) |
3de63c3f MW |
316 | only_include_assumed="# Explicit paths specified without -i nor -o; assuming --only paths..." |
317 | also= | |
318 | ;; | |
5a798fb5 JH |
319 | esac |
320 | unset only | |
6cbf07ef PB |
321 | case "$all,$interactive,$also,$#" in |
322 | *t,*t,*) | |
323 | die "Cannot use -a, --interactive or -i at the same time." ;; | |
cf7bb589 JH |
324 | t,,[1-9]*) |
325 | die "Paths with -a does not make sense." ;; | |
6cbf07ef PB |
326 | ,t,[1-9]*) |
327 | die "Paths with --interactive does not make sense." ;; | |
328 | ,,t,0) | |
cf7bb589 JH |
329 | die "No paths with -i does not make sense." ;; |
330 | esac | |
331 | ||
d1cc130a SG |
332 | if test ! -z "$templatefile" -a -z "$log_given" |
333 | then | |
334 | if test ! -f "$templatefile" | |
335 | then | |
336 | die "Commit template file does not exist." | |
337 | fi | |
338 | fi | |
339 | ||
cf7bb589 JH |
340 | ################################################################ |
341 | # Prepare index to have a tree to be committed | |
5a798fb5 | 342 | |
130fcca6 | 343 | case "$all,$also" in |
130fcca6 | 344 | t,) |
755b99d8 FK |
345 | if test ! -f "$THIS_INDEX" |
346 | then | |
347 | die 'nothing to commit (use "git add file1 file2" to include for commit)' | |
348 | fi | |
5a798fb5 | 349 | save_index && |
130fcca6 | 350 | ( |
514c09fd JH |
351 | cd_to_toplevel && |
352 | GIT_INDEX_FILE="$NEXT_INDEX" && | |
353 | export GIT_INDEX_FILE && | |
5be60078 JH |
354 | git diff-files --name-only -z | |
355 | git update-index --remove -z --stdin | |
514c09fd | 356 | ) || exit |
6a0049c0 | 357 | ;; |
130fcca6 | 358 | ,t) |
5a798fb5 | 359 | save_index && |
5be60078 | 360 | git ls-files --error-unmatch -- "$@" >/dev/null || exit |
bba319b5 | 361 | |
5be60078 | 362 | git diff-files --name-only -z -- "$@" | |
cf7bb589 | 363 | ( |
514c09fd JH |
364 | cd_to_toplevel && |
365 | GIT_INDEX_FILE="$NEXT_INDEX" && | |
366 | export GIT_INDEX_FILE && | |
5be60078 | 367 | git update-index --remove -z --stdin |
514c09fd | 368 | ) || exit |
22cff6a5 | 369 | ;; |
130fcca6 | 370 | ,) |
6cbf07ef PB |
371 | if test "$interactive" = t; then |
372 | git add --interactive || exit | |
373 | fi | |
130fcca6 JH |
374 | case "$#" in |
375 | 0) | |
3de63c3f | 376 | ;; # commit as-is |
130fcca6 | 377 | *) |
3de63c3f MW |
378 | if test -f "$GIT_DIR/MERGE_HEAD" |
379 | then | |
380 | refuse_partial "Cannot do a partial commit during a merge." | |
381 | fi | |
382 | TMP_INDEX="$GIT_DIR/tmp-index$$" | |
5be60078 | 383 | commit_only=`git ls-files --error-unmatch -- "$@"` || exit |
cf7bb589 | 384 | |
158d0577 | 385 | # Build a temporary index and update the real index |
3de63c3f MW |
386 | # the same way. |
387 | if test -z "$initial_commit" | |
388 | then | |
5e7f56ac | 389 | GIT_INDEX_FILE="$THIS_INDEX" \ |
5be60078 | 390 | git read-tree --index-output="$TMP_INDEX" -i -m HEAD |
3de63c3f MW |
391 | else |
392 | rm -f "$TMP_INDEX" | |
393 | fi || exit | |
cf7bb589 | 394 | |
293623ed | 395 | printf '%s\n' "$commit_only" | |
3de63c3f | 396 | GIT_INDEX_FILE="$TMP_INDEX" \ |
5be60078 | 397 | git update-index --add --remove --stdin && |
cf7bb589 | 398 | |
3de63c3f | 399 | save_index && |
293623ed | 400 | printf '%s\n' "$commit_only" | |
3de63c3f MW |
401 | ( |
402 | GIT_INDEX_FILE="$NEXT_INDEX" | |
403 | export GIT_INDEX_FILE | |
5be60078 | 404 | git update-index --remove --stdin |
3de63c3f MW |
405 | ) || exit |
406 | ;; | |
130fcca6 JH |
407 | esac |
408 | ;; | |
409 | esac | |
410 | ||
cf7bb589 JH |
411 | ################################################################ |
412 | # If we do as-is commit, the index file will be THIS_INDEX, | |
413 | # otherwise NEXT_INDEX after we make this commit. We leave | |
414 | # the index as is if we abort. | |
130fcca6 | 415 | |
cf7bb589 | 416 | if test -f "$NEXT_INDEX" |
130fcca6 | 417 | then |
cf7bb589 JH |
418 | USE_INDEX="$NEXT_INDEX" |
419 | else | |
420 | USE_INDEX="$THIS_INDEX" | |
130fcca6 JH |
421 | fi |
422 | ||
2b5f9a8c JH |
423 | case "$status_only" in |
424 | t) | |
425 | # This will silently fail in a read-only repository, which is | |
426 | # what we want. | |
5be60078 | 427 | GIT_INDEX_FILE="$USE_INDEX" git update-index -q --unmerged --refresh |
cf7bb589 JH |
428 | run_status |
429 | exit $? | |
2b5f9a8c JH |
430 | ;; |
431 | '') | |
5be60078 | 432 | GIT_INDEX_FILE="$USE_INDEX" git update-index -q --refresh || exit |
2b5f9a8c | 433 | ;; |
cf7bb589 JH |
434 | esac |
435 | ||
436 | ################################################################ | |
437 | # Grab commit message, write out tree and make commit. | |
438 | ||
130fcca6 JH |
439 | if test t = "$verify" && test -x "$GIT_DIR"/hooks/pre-commit |
440 | then | |
441 | if test "$TMP_INDEX" | |
442 | then | |
443 | GIT_INDEX_FILE="$TMP_INDEX" "$GIT_DIR"/hooks/pre-commit | |
444 | else | |
cf7bb589 | 445 | GIT_INDEX_FILE="$USE_INDEX" "$GIT_DIR"/hooks/pre-commit |
130fcca6 JH |
446 | fi || exit |
447 | fi | |
0cfe1d30 | 448 | |
aba2da13 JH |
449 | if test "$log_message" != '' |
450 | then | |
293623ed | 451 | printf '%s\n' "$log_message" |
aba2da13 JH |
452 | elif test "$logfile" != "" |
453 | then | |
454 | if test "$logfile" = - | |
455 | then | |
456 | test -t 0 && | |
457 | echo >&2 "(reading log message from standard input)" | |
458 | cat | |
459 | else | |
460 | cat <"$logfile" | |
461 | fi | |
462 | elif test "$use_commit" != "" | |
463 | then | |
e0d10e1c | 464 | encoding=$(git config i18n.commitencoding || echo UTF-8) |
5ac2715f JH |
465 | git show -s --pretty=raw --encoding="$encoding" "$use_commit" | |
466 | sed -e '1,/^$/d' -e 's/^ //' | |
a9cb3c6e | 467 | elif test -f "$GIT_DIR/MERGE_MSG" |
e5215804 JH |
468 | then |
469 | cat "$GIT_DIR/MERGE_MSG" | |
7d0c6887 JH |
470 | elif test -f "$GIT_DIR/SQUASH_MSG" |
471 | then | |
472 | cat "$GIT_DIR/SQUASH_MSG" | |
d1cc130a SG |
473 | elif test "$templatefile" != "" |
474 | then | |
475 | cat "$templatefile" | |
5be60078 | 476 | fi | git stripspace >"$GIT_DIR"/COMMIT_EDITMSG |
2d569933 JH |
477 | |
478 | case "$signoff" in | |
479 | t) | |
a7342913 GP |
480 | sign=$(git-var GIT_COMMITTER_IDENT | sed -e ' |
481 | s/>.*/>/ | |
482 | s/^/Signed-off-by: / | |
483 | ') | |
484 | blank_before_signoff= | |
dbaa06a2 | 485 | tail -n 1 "$GIT_DIR"/COMMIT_EDITMSG | |
a7342913 GP |
486 | grep 'Signed-off-by:' >/dev/null || blank_before_signoff=' |
487 | ' | |
488 | tail -n 1 "$GIT_DIR"/COMMIT_EDITMSG | | |
489 | grep "$sign"$ >/dev/null || | |
490 | printf '%s%s\n' "$blank_before_signoff" "$sign" \ | |
491 | >>"$GIT_DIR"/COMMIT_EDITMSG | |
2d569933 JH |
492 | ;; |
493 | esac | |
494 | ||
475443c8 | 495 | if test -f "$GIT_DIR/MERGE_HEAD" && test -z "$no_edit"; then |
2d569933 | 496 | echo "#" |
b6ae5409 | 497 | echo "# It looks like you may be committing a MERGE." |
2d569933 | 498 | echo "# If this is not correct, please remove the file" |
293623ed | 499 | printf '%s\n' "# $GIT_DIR/MERGE_HEAD" |
2d569933 JH |
500 | echo "# and try again" |
501 | echo "#" | |
f8e2c54c | 502 | fi >>"$GIT_DIR"/COMMIT_EDITMSG |
aba2da13 | 503 | |
130fcca6 | 504 | # Author |
83e24dce | 505 | if test '' != "$use_commit" |
130fcca6 | 506 | then |
0cae2346 JS |
507 | eval "$(get_author_ident_from_commit "$use_commit")" |
508 | export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE | |
130fcca6 | 509 | fi |
83e24dce JH |
510 | if test '' != "$force_author" |
511 | then | |
512 | GIT_AUTHOR_NAME=`expr "z$force_author" : 'z\(.*[^ ]\) *<.*'` && | |
513 | GIT_AUTHOR_EMAIL=`expr "z$force_author" : '.*\(<.*\)'` && | |
514 | test '' != "$GIT_AUTHOR_NAME" && | |
515 | test '' != "$GIT_AUTHOR_EMAIL" || | |
516 | die "malformed --author parameter" | |
517 | export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL | |
518 | fi | |
130fcca6 | 519 | |
96069cf0 | 520 | PARENTS="-p HEAD" |
130fcca6 | 521 | if test -z "$initial_commit" |
8098a178 | 522 | then |
a3a733e6 | 523 | rloga='commit' |
5fec3ef1 | 524 | if [ -f "$GIT_DIR/MERGE_HEAD" ]; then |
a3a733e6 | 525 | rloga='commit (merge)' |
91063bbc | 526 | PARENTS="-p HEAD "`sed -e 's/^/-p /' "$GIT_DIR/MERGE_HEAD"` |
b4019f04 | 527 | elif test -n "$amend"; then |
a3a733e6 | 528 | rloga='commit (amend)' |
5be60078 | 529 | PARENTS=$(git cat-file commit HEAD | |
b4019f04 | 530 | sed -n -e '/^$/q' -e 's/^parent /-p /p') |
aba2da13 | 531 | fi |
5be60078 | 532 | current="$(git rev-parse --verify HEAD)" |
8098a178 | 533 | else |
5be60078 | 534 | if [ -z "$(git ls-files)" ]; then |
aeb80c70 | 535 | echo >&2 'nothing to commit (use "git add file1 file2" to include for commit)' |
8098a178 JH |
536 | exit 1 |
537 | fi | |
538 | PARENTS="" | |
a3a733e6 | 539 | rloga='commit (initial)' |
cede7526 | 540 | current='' |
96069cf0 | 541 | fi |
23913dc7 | 542 | set_reflog_action "$rloga" |
130fcca6 | 543 | |
475443c8 JH |
544 | if test -z "$no_edit" |
545 | then | |
546 | { | |
88a15314 MW |
547 | echo "" |
548 | echo "# Please enter the commit message for your changes." | |
549 | echo "# (Comment lines starting with '#' will not be included)" | |
475443c8 JH |
550 | test -z "$only_include_assumed" || echo "$only_include_assumed" |
551 | run_status | |
552 | } >>"$GIT_DIR"/COMMIT_EDITMSG | |
553 | else | |
554 | # we need to check if there is anything to commit | |
a6080a0a | 555 | run_status >/dev/null |
475443c8 | 556 | fi |
8588452c | 557 | if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" -a -z "$amend" ] |
a3e870f2 | 558 | then |
7d0c6887 | 559 | rm -f "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG" |
09b0d9dd | 560 | use_status_color=t |
5a798fb5 | 561 | run_status |
a3e870f2 LT |
562 | exit 1 |
563 | fi | |
475443c8 | 564 | |
0c091296 | 565 | case "$no_edit" in |
5fec3ef1 | 566 | '') |
ec4e69c0 SE |
567 | git-var GIT_AUTHOR_IDENT > /dev/null || die |
568 | git-var GIT_COMMITTER_IDENT > /dev/null || die | |
ef0c2abf | 569 | git_editor "$GIT_DIR/COMMIT_EDITMSG" |
5fec3ef1 JH |
570 | ;; |
571 | esac | |
89e2c5f1 JH |
572 | |
573 | case "$verify" in | |
574 | t) | |
575 | if test -x "$GIT_DIR"/hooks/commit-msg | |
576 | then | |
f8e2c54c | 577 | "$GIT_DIR"/hooks/commit-msg "$GIT_DIR"/COMMIT_EDITMSG || exit |
89e2c5f1 JH |
578 | fi |
579 | esac | |
580 | ||
29f4ad86 YD |
581 | if test -z "$no_edit" |
582 | then | |
583 | sed -e ' | |
584 | /^diff --git a\/.*/{ | |
585 | s/// | |
586 | q | |
587 | } | |
588 | /^#/d | |
589 | ' "$GIT_DIR"/COMMIT_EDITMSG | |
590 | else | |
591 | cat "$GIT_DIR"/COMMIT_EDITMSG | |
592 | fi | | |
5be60078 | 593 | git stripspace >"$GIT_DIR"/COMMIT_MSG |
f8e2c54c | 594 | |
d1cc130a SG |
595 | # Test whether the commit message has any content we didn't supply. |
596 | have_commitmsg= | |
597 | grep -v -i '^Signed-off-by' "$GIT_DIR"/COMMIT_MSG | | |
598 | git stripspace > "$GIT_DIR"/COMMIT_BAREMSG | |
599 | ||
600 | # Is the commit message totally empty? | |
601 | if test -s "$GIT_DIR"/COMMIT_BAREMSG | |
602 | then | |
603 | if test "$templatefile" != "" | |
604 | then | |
605 | # Test whether this is just the unaltered template. | |
606 | if cnt=`sed -e '/^#/d' < "$templatefile" | | |
607 | git stripspace | | |
608 | diff "$GIT_DIR"/COMMIT_BAREMSG - | | |
609 | wc -l` && | |
610 | test 0 -lt $cnt | |
611 | then | |
612 | have_commitmsg=t | |
613 | fi | |
614 | else | |
615 | # No template, so the content in the commit message must | |
616 | # have come from the user. | |
617 | have_commitmsg=t | |
618 | fi | |
619 | fi | |
620 | ||
621 | rm -f "$GIT_DIR"/COMMIT_BAREMSG | |
622 | ||
623 | if test "$have_commitmsg" = "t" | |
0c091296 | 624 | then |
130fcca6 JH |
625 | if test -z "$TMP_INDEX" |
626 | then | |
5be60078 | 627 | tree=$(GIT_INDEX_FILE="$USE_INDEX" git write-tree) |
130fcca6 | 628 | else |
5be60078 | 629 | tree=$(GIT_INDEX_FILE="$TMP_INDEX" git write-tree) && |
130fcca6 JH |
630 | rm -f "$TMP_INDEX" |
631 | fi && | |
9d6f220c | 632 | commit=$(git commit-tree $tree $PARENTS <"$GIT_DIR/COMMIT_MSG") && |
67644a4d | 633 | rlogm=$(sed -e 1q "$GIT_DIR"/COMMIT_MSG) && |
5be60078 | 634 | git update-ref -m "$GIT_REFLOG_ACTION: $rlogm" HEAD $commit "$current" && |
a9cb3c6e | 635 | rm -f -- "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/MERGE_MSG" && |
cf7bb589 JH |
636 | if test -f "$NEXT_INDEX" |
637 | then | |
638 | mv "$NEXT_INDEX" "$THIS_INDEX" | |
639 | else | |
640 | : ;# happy | |
641 | fi | |
0c091296 JH |
642 | else |
643 | echo >&2 "* no commit message? aborting commit." | |
644 | false | |
645 | fi | |
170241b7 | 646 | ret="$?" |
7d0c6887 | 647 | rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG" |
c93d88a5 JH |
648 | |
649 | cd_to_toplevel | |
650 | ||
b4372ef1 | 651 | git rerere |
89e2c5f1 | 652 | |
ebd124c6 | 653 | if test "$ret" = 0 |
89e2c5f1 | 654 | then |
ebd124c6 NP |
655 | if test -x "$GIT_DIR"/hooks/post-commit |
656 | then | |
657 | "$GIT_DIR"/hooks/post-commit | |
658 | fi | |
659 | if test -z "$quiet" | |
660 | then | |
5be60078 | 661 | commit=`git diff-tree --always --shortstat --pretty="format:%h: %s"\ |
c7263d4d | 662 | --summary --root HEAD --` |
ebd124c6 | 663 | echo "Created${initial_commit:+ initial} commit $commit" |
ebd124c6 | 664 | fi |
89e2c5f1 | 665 | fi |
61f5cb7f | 666 | |
170241b7 | 667 | exit "$ret" |