]>
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 | ||
443f8338 | 6 | USAGE='[-a] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit>] [-u] [--amend] [-e] [--author <author>] [[-i | -o] <path>...]' |
130fcca6 | 7 | SUBDIRECTORY_OK=Yes |
ae2b0f15 | 8 | . git-sh-setup |
b33e9666 | 9 | |
cf7bb589 JH |
10 | git-rev-parse --verify HEAD >/dev/null 2>&1 || initial_commit=t |
11 | branch=$(GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD) | |
12 | ||
13 | case "$0" in | |
14 | *status) | |
15 | status_only=t | |
16 | unmerged_ok_if_status=--unmerged ;; | |
17 | *commit) | |
18 | status_only= | |
19 | unmerged_ok_if_status= ;; | |
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 | ||
35 | report () { | |
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" ] | |
5a798fb5 JH |
60 | } |
61 | ||
62 | run_status () { | |
cf7bb589 JH |
63 | ( |
64 | # We always show status for the whole tree. | |
65 | cd "$TOP" | |
66 | ||
b4019f04 JH |
67 | IS_INITIAL="$initial_commit" |
68 | REFERENCE=HEAD | |
69 | case "$amend" in | |
70 | t) | |
71 | # If we are amending the initial commit, there | |
72 | # is no HEAD^1. | |
73 | if git-rev-parse --verify "HEAD^1" >/dev/null 2>&1 | |
74 | then | |
75 | REFERENCE="HEAD^1" | |
76 | IS_INITIAL= | |
77 | else | |
78 | IS_INITIAL=t | |
79 | fi | |
80 | ;; | |
81 | esac | |
82 | ||
cf7bb589 JH |
83 | # If TMP_INDEX is defined, that means we are doing |
84 | # "--only" partial commit, and that index file is used | |
85 | # to build the tree for the commit. Otherwise, if | |
86 | # NEXT_INDEX exists, that is the index file used to | |
87 | # make the commit. Otherwise we are using as-is commit | |
88 | # so the regular index file is what we use to compare. | |
89 | if test '' != "$TMP_INDEX" | |
90 | then | |
91 | GIT_INDEX_FILE="$TMP_INDEX" | |
92 | export GIT_INDEX_FILE | |
93 | elif test -f "$NEXT_INDEX" | |
94 | then | |
95 | GIT_INDEX_FILE="$NEXT_INDEX" | |
96 | export GIT_INDEX_FILE | |
97 | fi | |
98 | ||
99 | case "$branch" in | |
100 | refs/heads/master) ;; | |
101 | *) echo "# On branch $branch" ;; | |
102 | esac | |
103 | ||
b4019f04 | 104 | if test -z "$IS_INITIAL" |
cf7bb589 | 105 | then |
9ae6be80 | 106 | git-diff-index -M --cached --name-status \ |
b4019f04 | 107 | --diff-filter=MDTCRA $REFERENCE | |
9ae6be80 JH |
108 | sed -e ' |
109 | s/\\/\\\\/g | |
110 | s/ /\\ /g | |
111 | ' | | |
112 | report "Updated but not checked in" "will commit" | |
cf7bb589 JH |
113 | committable="$?" |
114 | else | |
115 | echo '# | |
116 | # Initial commit | |
117 | #' | |
118 | git-ls-files | | |
119 | sed -e ' | |
120 | s/\\/\\\\/g | |
121 | s/ /\\ /g | |
122 | s/^/A / | |
123 | ' | | |
124 | report "Updated but not checked in" "will commit" | |
125 | ||
126 | committable="$?" | |
127 | fi | |
128 | ||
129 | git-diff-files --name-status | | |
130 | sed -e ' | |
131 | s/\\/\\\\/g | |
132 | s/ /\\ /g | |
133 | ' | | |
134 | report "Changed but not updated" \ | |
135 | "use git-update-index to mark for commit" | |
136 | ||
443f8338 ML |
137 | option="" |
138 | if test -z "$untracked_files"; then | |
139 | option="--directory --no-empty-directory" | |
140 | fi | |
3dffd2c8 | 141 | hdr_shown= |
cf7bb589 JH |
142 | if test -f "$GIT_DIR/info/exclude" |
143 | then | |
3dffd2c8 | 144 | git-ls-files --others $option \ |
cf7bb589 JH |
145 | --exclude-from="$GIT_DIR/info/exclude" \ |
146 | --exclude-per-directory=.gitignore | |
147 | else | |
3dffd2c8 | 148 | git-ls-files --others $option \ |
cf7bb589 JH |
149 | --exclude-per-directory=.gitignore |
150 | fi | | |
3dffd2c8 AR |
151 | while read line; do |
152 | if [ -z "$hdr_shown" ]; then | |
153 | echo '#' | |
154 | echo '# Untracked files:' | |
155 | echo '# (use "git add" to add to commit)' | |
156 | echo '#' | |
157 | hdr_shown=1 | |
158 | fi | |
159 | echo "# $line" | |
160 | done | |
9ae6be80 | 161 | |
1fa7a68f | 162 | if test -n "$verbose" -a -z "$IS_INITIAL" |
9ae6be80 | 163 | then |
b4019f04 | 164 | git-diff-index --cached -M -p --diff-filter=MDTCRA $REFERENCE |
9ae6be80 | 165 | fi |
cf7bb589 JH |
166 | case "$committable" in |
167 | 0) | |
6a74642c JH |
168 | case "$amend" in |
169 | t) | |
170 | echo "# No changes" ;; | |
171 | *) | |
172 | echo "nothing to commit" ;; | |
173 | esac | |
174 | exit 1 ;; | |
cf7bb589 JH |
175 | esac |
176 | exit 0 | |
177 | ) | |
5a798fb5 JH |
178 | } |
179 | ||
cf7bb589 JH |
180 | trap ' |
181 | test -z "$TMP_INDEX" || { | |
182 | test -f "$TMP_INDEX" && rm -f "$TMP_INDEX" | |
183 | } | |
184 | rm -f "$NEXT_INDEX" | |
185 | ' 0 | |
186 | ||
187 | ################################################################ | |
188 | # Command line argument parsing and sanity checking | |
189 | ||
130fcca6 JH |
190 | all= |
191 | also= | |
5a798fb5 | 192 | only= |
130fcca6 JH |
193 | logfile= |
194 | use_commit= | |
b4019f04 | 195 | amend= |
cda8ab59 | 196 | edit_flag= |
130fcca6 JH |
197 | no_edit= |
198 | log_given= | |
199 | log_message= | |
200 | verify=t | |
cf7bb589 | 201 | verbose= |
130fcca6 JH |
202 | signoff= |
203 | force_author= | |
bba319b5 | 204 | only_include_assumed= |
443f8338 | 205 | untracked_files= |
0c091296 | 206 | while case "$#" in 0) break;; esac |
5fec3ef1 | 207 | do |
0c091296 | 208 | case "$1" in |
130fcca6 JH |
209 | -F|--F|-f|--f|--fi|--fil|--file) |
210 | case "$#" in 1) usage ;; esac | |
211 | shift | |
212 | no_edit=t | |
213 | log_given=t$log_given | |
214 | logfile="$1" | |
215 | shift | |
216 | ;; | |
217 | -F*|-f*) | |
218 | no_edit=t | |
219 | log_given=t$log_given | |
8096fae7 | 220 | logfile=`expr "z$1" : 'z-[Ff]\(.*\)'` |
130fcca6 JH |
221 | shift |
222 | ;; | |
223 | --F=*|--f=*|--fi=*|--fil=*|--file=*) | |
224 | no_edit=t | |
225 | log_given=t$log_given | |
8096fae7 | 226 | logfile=`expr "z$1" : 'z-[^=]*=\(.*\)'` |
130fcca6 JH |
227 | shift |
228 | ;; | |
0c091296 | 229 | -a|--a|--al|--all) |
130fcca6 JH |
230 | all=t |
231 | shift | |
232 | ;; | |
233 | --au=*|--aut=*|--auth=*|--autho=*|--author=*) | |
8096fae7 | 234 | force_author=`expr "z$1" : 'z-[^=]*=\(.*\)'` |
130fcca6 JH |
235 | shift |
236 | ;; | |
237 | --au|--aut|--auth|--autho|--author) | |
238 | case "$#" in 1) usage ;; esac | |
239 | shift | |
240 | force_author="$1" | |
241 | shift | |
242 | ;; | |
243 | -e|--e|--ed|--edi|--edit) | |
cda8ab59 | 244 | edit_flag=t |
130fcca6 JH |
245 | shift |
246 | ;; | |
247 | -i|--i|--in|--inc|--incl|--inclu|--includ|--include) | |
248 | also=t | |
249 | shift | |
250 | ;; | |
5a798fb5 JH |
251 | -o|--o|--on|--onl|--only) |
252 | only=t | |
253 | shift | |
254 | ;; | |
0c091296 | 255 | -m|--m|--me|--mes|--mess|--messa|--messag|--message) |
130fcca6 JH |
256 | case "$#" in 1) usage ;; esac |
257 | shift | |
6891281c SP |
258 | log_given=m$log_given |
259 | if test "$log_message" = '' | |
260 | then | |
261 | log_message="$1" | |
262 | else | |
263 | log_message="$log_message | |
264 | ||
265 | $1" | |
266 | fi | |
130fcca6 JH |
267 | no_edit=t |
268 | shift | |
269 | ;; | |
270 | -m*) | |
6891281c SP |
271 | log_given=m$log_given |
272 | if test "$log_message" = '' | |
273 | then | |
8096fae7 | 274 | log_message=`expr "z$1" : 'z-m\(.*\)'` |
6891281c SP |
275 | else |
276 | log_message="$log_message | |
277 | ||
8096fae7 | 278 | `expr "z$1" : 'z-m\(.*\)'`" |
6891281c | 279 | fi |
130fcca6 JH |
280 | no_edit=t |
281 | shift | |
282 | ;; | |
283 | --m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*) | |
6891281c SP |
284 | log_given=m$log_given |
285 | if test "$log_message" = '' | |
286 | then | |
8096fae7 | 287 | log_message=`expr "z$1" : 'z-[^=]*=\(.*\)'` |
6891281c SP |
288 | else |
289 | log_message="$log_message | |
290 | ||
8096fae7 | 291 | `expr "z$1" : 'zq-[^=]*=\(.*\)'`" |
6891281c | 292 | fi |
130fcca6 JH |
293 | no_edit=t |
294 | shift | |
295 | ;; | |
296 | -n|--n|--no|--no-|--no-v|--no-ve|--no-ver|--no-veri|--no-verif|--no-verify) | |
297 | verify= | |
298 | shift | |
299 | ;; | |
b4019f04 JH |
300 | --a|--am|--ame|--amen|--amend) |
301 | amend=t | |
302 | log_given=t$log_given | |
303 | use_commit=HEAD | |
304 | shift | |
305 | ;; | |
130fcca6 JH |
306 | -c) |
307 | case "$#" in 1) usage ;; esac | |
308 | shift | |
309 | log_given=t$log_given | |
310 | use_commit="$1" | |
311 | no_edit= | |
312 | shift | |
313 | ;; | |
314 | --ree=*|--reed=*|--reedi=*|--reedit=*|--reedit-=*|--reedit-m=*|\ | |
0c091296 JH |
315 | --reedit-me=*|--reedit-mes=*|--reedit-mess=*|--reedit-messa=*|\ |
316 | --reedit-messag=*|--reedit-message=*) | |
130fcca6 | 317 | log_given=t$log_given |
8096fae7 | 318 | use_commit=`expr "z$1" : 'z-[^=]*=\(.*\)'` |
130fcca6 JH |
319 | no_edit= |
320 | shift | |
321 | ;; | |
322 | --ree|--reed|--reedi|--reedit|--reedit-|--reedit-m|--reedit-me|\ | |
0c091296 | 323 | --reedit-mes|--reedit-mess|--reedit-messa|--reedit-messag|--reedit-message) |
130fcca6 JH |
324 | case "$#" in 1) usage ;; esac |
325 | shift | |
326 | log_given=t$log_given | |
327 | use_commit="$1" | |
328 | no_edit= | |
329 | shift | |
330 | ;; | |
331 | -C) | |
332 | case "$#" in 1) usage ;; esac | |
333 | shift | |
334 | log_given=t$log_given | |
335 | use_commit="$1" | |
336 | no_edit=t | |
337 | shift | |
338 | ;; | |
339 | --reu=*|--reus=*|--reuse=*|--reuse-=*|--reuse-m=*|--reuse-me=*|\ | |
0c091296 JH |
340 | --reuse-mes=*|--reuse-mess=*|--reuse-messa=*|--reuse-messag=*|\ |
341 | --reuse-message=*) | |
130fcca6 | 342 | log_given=t$log_given |
8096fae7 | 343 | use_commit=`expr "z$1" : 'z-[^=]*=\(.*\)'` |
130fcca6 JH |
344 | no_edit=t |
345 | shift | |
346 | ;; | |
347 | --reu|--reus|--reuse|--reuse-|--reuse-m|--reuse-me|--reuse-mes|\ | |
0c091296 | 348 | --reuse-mess|--reuse-messa|--reuse-messag|--reuse-message) |
130fcca6 JH |
349 | case "$#" in 1) usage ;; esac |
350 | shift | |
351 | log_given=t$log_given | |
352 | use_commit="$1" | |
353 | no_edit=t | |
354 | shift | |
355 | ;; | |
0cfe1d30 | 356 | -s|--s|--si|--sig|--sign|--signo|--signof|--signoff) |
130fcca6 JH |
357 | signoff=t |
358 | shift | |
359 | ;; | |
cf7bb589 JH |
360 | -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose) |
361 | verbose=t | |
362 | shift | |
130fcca6 | 363 | ;; |
443f8338 ML |
364 | -u|--u|--un|--unt|--untr|--untra|--untrac|--untrack|--untracke|--untracked|\ |
365 | --untracked-|--untracked-f|--untracked-fi|--untracked-fil|--untracked-file|\ | |
366 | --untracked-files) | |
367 | untracked_files=t | |
368 | shift | |
369 | ;; | |
0c091296 | 370 | --) |
130fcca6 JH |
371 | shift |
372 | break | |
373 | ;; | |
0c091296 | 374 | -*) |
130fcca6 JH |
375 | usage |
376 | ;; | |
0c091296 | 377 | *) |
130fcca6 JH |
378 | break |
379 | ;; | |
0c091296 | 380 | esac |
5fec3ef1 | 381 | done |
cda8ab59 | 382 | case "$edit_flag" in t) no_edit= ;; esac |
5fec3ef1 | 383 | |
cf7bb589 JH |
384 | ################################################################ |
385 | # Sanity check options | |
386 | ||
b4019f04 JH |
387 | case "$amend,$initial_commit" in |
388 | t,t) | |
389 | die "You do not have anything to amend." ;; | |
390 | t,) | |
391 | if [ -f "$GIT_DIR/MERGE_HEAD" ]; then | |
392 | die "You are in the middle of a merge -- cannot amend." | |
393 | fi ;; | |
394 | esac | |
395 | ||
0c091296 JH |
396 | case "$log_given" in |
397 | tt*) | |
6891281c SP |
398 | die "Only one of -c/-C/-F can be used." ;; |
399 | *tm*|*mt*) | |
400 | die "Option -m cannot be combined with -c/-C/-F." ;; | |
0c091296 JH |
401 | esac |
402 | ||
6a74642c JH |
403 | case "$#,$also,$only,$amend" in |
404 | *,t,t,*) | |
5a798fb5 | 405 | die "Only one of --include/--only can be used." ;; |
6a74642c | 406 | 0,t,,* | 0,,t,) |
5a798fb5 | 407 | die "No paths with --include/--only does not make sense." ;; |
6a74642c JH |
408 | 0,,t,t) |
409 | only_include_assumed="# Clever... amending the last one with dirty index." ;; | |
410 | 0,,,*) | |
5a798fb5 | 411 | ;; |
6a74642c | 412 | *,,,*) |
756e3ee0 | 413 | only_include_assumed="# Explicit paths specified without -i nor -o; assuming --only paths..." |
4170a195 | 414 | also= |
5a798fb5 JH |
415 | ;; |
416 | esac | |
417 | unset only | |
cf7bb589 JH |
418 | case "$all,$also,$#" in |
419 | t,t,*) | |
420 | die "Cannot use -a and -i at the same time." ;; | |
421 | t,,[1-9]*) | |
422 | die "Paths with -a does not make sense." ;; | |
423 | ,t,0) | |
424 | die "No paths with -i does not make sense." ;; | |
425 | esac | |
426 | ||
427 | ################################################################ | |
428 | # Prepare index to have a tree to be committed | |
5a798fb5 | 429 | |
130fcca6 | 430 | TOP=`git-rev-parse --show-cdup` |
5a798fb5 JH |
431 | if test -z "$TOP" |
432 | then | |
433 | TOP=./ | |
434 | fi | |
130fcca6 JH |
435 | |
436 | case "$all,$also" in | |
130fcca6 | 437 | t,) |
5a798fb5 | 438 | save_index && |
130fcca6 | 439 | ( |
5a798fb5 | 440 | cd "$TOP" |
cf7bb589 JH |
441 | GIT_INDEX_FILE="$NEXT_INDEX" |
442 | export GIT_INDEX_FILE | |
130fcca6 JH |
443 | git-diff-files --name-only -z | |
444 | git-update-index --remove -z --stdin | |
445 | ) | |
6a0049c0 | 446 | ;; |
130fcca6 | 447 | ,t) |
5a798fb5 | 448 | save_index && |
bba319b5 JH |
449 | git-ls-files --error-unmatch -- "$@" >/dev/null || exit |
450 | ||
130fcca6 | 451 | git-diff-files --name-only -z -- "$@" | |
cf7bb589 JH |
452 | ( |
453 | cd "$TOP" | |
454 | GIT_INDEX_FILE="$NEXT_INDEX" | |
455 | export GIT_INDEX_FILE | |
456 | git-update-index --remove -z --stdin | |
457 | ) | |
22cff6a5 | 458 | ;; |
130fcca6 JH |
459 | ,) |
460 | case "$#" in | |
461 | 0) | |
462 | ;; # commit as-is | |
463 | *) | |
464 | if test -f "$GIT_DIR/MERGE_HEAD" | |
465 | then | |
466 | refuse_partial "Cannot do a partial commit during a merge." | |
467 | fi | |
468 | TMP_INDEX="$GIT_DIR/tmp-index$$" | |
469 | if test -z "$initial_commit" | |
470 | then | |
471 | # make sure index is clean at the specified paths, or | |
472 | # they are additions. | |
473 | dirty_in_index=`git-diff-index --cached --name-status \ | |
5a798fb5 | 474 | --diff-filter=DMTU HEAD -- "$@"` |
130fcca6 | 475 | test -z "$dirty_in_index" || |
5a798fb5 | 476 | refuse_partial "Different in index and the last commit: |
130fcca6 JH |
477 | $dirty_in_index" |
478 | fi | |
bba319b5 | 479 | commit_only=`git-ls-files --error-unmatch -- "$@"` || exit |
cf7bb589 JH |
480 | |
481 | # Build the temporary index and update the real index | |
482 | # the same way. | |
483 | if test -z "$initial_commit" | |
484 | then | |
485 | cp "$THIS_INDEX" "$TMP_INDEX" | |
486 | GIT_INDEX_FILE="$TMP_INDEX" git-read-tree -m HEAD | |
487 | else | |
488 | rm -f "$TMP_INDEX" | |
489 | fi || exit | |
490 | ||
491 | echo "$commit_only" | | |
492 | GIT_INDEX_FILE="$TMP_INDEX" \ | |
493 | git-update-index --add --remove --stdin && | |
494 | ||
495 | save_index && | |
496 | echo "$commit_only" | | |
497 | ( | |
498 | GIT_INDEX_FILE="$NEXT_INDEX" | |
499 | export GIT_INDEX_FILE | |
500 | git-update-index --remove --stdin | |
501 | ) || exit | |
502 | ;; | |
130fcca6 JH |
503 | esac |
504 | ;; | |
505 | esac | |
506 | ||
cf7bb589 JH |
507 | ################################################################ |
508 | # If we do as-is commit, the index file will be THIS_INDEX, | |
509 | # otherwise NEXT_INDEX after we make this commit. We leave | |
510 | # the index as is if we abort. | |
130fcca6 | 511 | |
cf7bb589 | 512 | if test -f "$NEXT_INDEX" |
130fcca6 | 513 | then |
cf7bb589 JH |
514 | USE_INDEX="$NEXT_INDEX" |
515 | else | |
516 | USE_INDEX="$THIS_INDEX" | |
130fcca6 JH |
517 | fi |
518 | ||
cf7bb589 JH |
519 | GIT_INDEX_FILE="$USE_INDEX" \ |
520 | git-update-index -q $unmerged_ok_if_status --refresh || exit | |
521 | ||
522 | ################################################################ | |
523 | # If the request is status, just show it and exit. | |
524 | ||
525 | case "$0" in | |
526 | *status) | |
527 | run_status | |
528 | exit $? | |
529 | esac | |
530 | ||
531 | ################################################################ | |
532 | # Grab commit message, write out tree and make commit. | |
533 | ||
130fcca6 JH |
534 | if test t = "$verify" && test -x "$GIT_DIR"/hooks/pre-commit |
535 | then | |
536 | if test "$TMP_INDEX" | |
537 | then | |
538 | GIT_INDEX_FILE="$TMP_INDEX" "$GIT_DIR"/hooks/pre-commit | |
539 | else | |
cf7bb589 | 540 | GIT_INDEX_FILE="$USE_INDEX" "$GIT_DIR"/hooks/pre-commit |
130fcca6 JH |
541 | fi || exit |
542 | fi | |
0cfe1d30 | 543 | |
aba2da13 JH |
544 | if test "$log_message" != '' |
545 | then | |
546 | echo "$log_message" | |
547 | elif test "$logfile" != "" | |
548 | then | |
549 | if test "$logfile" = - | |
550 | then | |
551 | test -t 0 && | |
552 | echo >&2 "(reading log message from standard input)" | |
553 | cat | |
554 | else | |
555 | cat <"$logfile" | |
556 | fi | |
557 | elif test "$use_commit" != "" | |
558 | then | |
559 | git-cat-file commit "$use_commit" | sed -e '1,/^$/d' | |
e5215804 JH |
560 | elif test -f "$GIT_DIR/MERGE_HEAD" && test -f "$GIT_DIR/MERGE_MSG" |
561 | then | |
562 | cat "$GIT_DIR/MERGE_MSG" | |
7d0c6887 JH |
563 | elif test -f "$GIT_DIR/SQUASH_MSG" |
564 | then | |
565 | cat "$GIT_DIR/SQUASH_MSG" | |
f8e2c54c | 566 | fi | git-stripspace >"$GIT_DIR"/COMMIT_EDITMSG |
2d569933 JH |
567 | |
568 | case "$signoff" in | |
569 | t) | |
f6413391 JH |
570 | { |
571 | echo | |
572 | git-var GIT_COMMITTER_IDENT | sed -e ' | |
573 | s/>.*/>/ | |
574 | s/^/Signed-off-by: / | |
575 | ' | |
f8e2c54c | 576 | } >>"$GIT_DIR"/COMMIT_EDITMSG |
2d569933 JH |
577 | ;; |
578 | esac | |
579 | ||
475443c8 | 580 | if test -f "$GIT_DIR/MERGE_HEAD" && test -z "$no_edit"; then |
2d569933 | 581 | echo "#" |
b6ae5409 | 582 | echo "# It looks like you may be committing a MERGE." |
2d569933 JH |
583 | echo "# If this is not correct, please remove the file" |
584 | echo "# $GIT_DIR/MERGE_HEAD" | |
585 | echo "# and try again" | |
586 | echo "#" | |
f8e2c54c | 587 | fi >>"$GIT_DIR"/COMMIT_EDITMSG |
aba2da13 | 588 | |
130fcca6 | 589 | # Author |
5a798fb5 JH |
590 | if test '' != "$force_author" |
591 | then | |
f327dbce MW |
592 | GIT_AUTHOR_NAME=`expr "z$force_author" : 'z\(.*[^ ]\) *<.*'` && |
593 | GIT_AUTHOR_EMAIL=`expr "z$force_author" : '.*\(<.*\)'` && | |
5a798fb5 JH |
594 | test '' != "$GIT_AUTHOR_NAME" && |
595 | test '' != "$GIT_AUTHOR_EMAIL" || | |
82e5a82f | 596 | die "malformed --author parameter" |
5a798fb5 JH |
597 | export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL |
598 | elif test '' != "$use_commit" | |
130fcca6 JH |
599 | then |
600 | pick_author_script=' | |
601 | /^author /{ | |
602 | s/'\''/'\''\\'\'\''/g | |
603 | h | |
604 | s/^author \([^<]*\) <[^>]*> .*$/\1/ | |
605 | s/'\''/'\''\'\'\''/g | |
606 | s/.*/GIT_AUTHOR_NAME='\''&'\''/p | |
607 | ||
608 | g | |
609 | s/^author [^<]* <\([^>]*\)> .*$/\1/ | |
610 | s/'\''/'\''\'\'\''/g | |
611 | s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p | |
612 | ||
613 | g | |
614 | s/^author [^<]* <[^>]*> \(.*\)$/\1/ | |
615 | s/'\''/'\''\'\'\''/g | |
616 | s/.*/GIT_AUTHOR_DATE='\''&'\''/p | |
617 | ||
618 | q | |
619 | } | |
620 | ' | |
621 | set_author_env=`git-cat-file commit "$use_commit" | | |
622 | LANG=C LC_ALL=C sed -ne "$pick_author_script"` | |
623 | eval "$set_author_env" | |
624 | export GIT_AUTHOR_NAME | |
625 | export GIT_AUTHOR_EMAIL | |
626 | export GIT_AUTHOR_DATE | |
130fcca6 JH |
627 | fi |
628 | ||
96069cf0 | 629 | PARENTS="-p HEAD" |
130fcca6 | 630 | if test -z "$initial_commit" |
8098a178 | 631 | then |
a3a733e6 | 632 | rloga='commit' |
5fec3ef1 | 633 | if [ -f "$GIT_DIR/MERGE_HEAD" ]; then |
a3a733e6 | 634 | rloga='commit (merge)' |
91063bbc | 635 | PARENTS="-p HEAD "`sed -e 's/^/-p /' "$GIT_DIR/MERGE_HEAD"` |
b4019f04 | 636 | elif test -n "$amend"; then |
a3a733e6 | 637 | rloga='commit (amend)' |
b4019f04 JH |
638 | PARENTS=$(git-cat-file commit HEAD | |
639 | sed -n -e '/^$/q' -e 's/^parent /-p /p') | |
aba2da13 | 640 | fi |
b8310152 | 641 | current=$(git-rev-parse --verify HEAD) |
8098a178 JH |
642 | else |
643 | if [ -z "$(git-ls-files)" ]; then | |
5a798fb5 | 644 | echo >&2 Nothing to commit |
8098a178 JH |
645 | exit 1 |
646 | fi | |
647 | PARENTS="" | |
b8310152 | 648 | current= |
a3a733e6 | 649 | rloga='commit (initial)' |
96069cf0 | 650 | fi |
130fcca6 | 651 | |
475443c8 JH |
652 | if test -z "$no_edit" |
653 | then | |
654 | { | |
88a15314 MW |
655 | echo "" |
656 | echo "# Please enter the commit message for your changes." | |
657 | echo "# (Comment lines starting with '#' will not be included)" | |
475443c8 JH |
658 | test -z "$only_include_assumed" || echo "$only_include_assumed" |
659 | run_status | |
660 | } >>"$GIT_DIR"/COMMIT_EDITMSG | |
661 | else | |
662 | # we need to check if there is anything to commit | |
663 | run_status >/dev/null | |
664 | fi | |
8588452c | 665 | if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" -a -z "$amend" ] |
a3e870f2 | 666 | then |
7d0c6887 | 667 | rm -f "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG" |
5a798fb5 | 668 | run_status |
a3e870f2 LT |
669 | exit 1 |
670 | fi | |
475443c8 | 671 | |
0c091296 | 672 | case "$no_edit" in |
5fec3ef1 | 673 | '') |
7334f06c JH |
674 | case "${VISUAL:-$EDITOR},$TERM" in |
675 | ,dumb) | |
676 | echo >&2 "Terminal is dumb but no VISUAL nor EDITOR defined." | |
677 | echo >&2 "Please supply the commit log message using either" | |
678 | echo >&2 "-m or -F option. A boilerplate log message has" | |
679 | echo >&2 "been prepared in $GIT_DIR/COMMIT_EDITMSG" | |
130fcca6 JH |
680 | exit 1 |
681 | ;; | |
7334f06c | 682 | esac |
ec4e69c0 SE |
683 | git-var GIT_AUTHOR_IDENT > /dev/null || die |
684 | git-var GIT_COMMITTER_IDENT > /dev/null || die | |
f8e2c54c | 685 | ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR/COMMIT_EDITMSG" |
5fec3ef1 JH |
686 | ;; |
687 | esac | |
89e2c5f1 JH |
688 | |
689 | case "$verify" in | |
690 | t) | |
691 | if test -x "$GIT_DIR"/hooks/commit-msg | |
692 | then | |
f8e2c54c | 693 | "$GIT_DIR"/hooks/commit-msg "$GIT_DIR"/COMMIT_EDITMSG || exit |
89e2c5f1 JH |
694 | fi |
695 | esac | |
696 | ||
29f4ad86 YD |
697 | if test -z "$no_edit" |
698 | then | |
699 | sed -e ' | |
700 | /^diff --git a\/.*/{ | |
701 | s/// | |
702 | q | |
703 | } | |
704 | /^#/d | |
705 | ' "$GIT_DIR"/COMMIT_EDITMSG | |
706 | else | |
707 | cat "$GIT_DIR"/COMMIT_EDITMSG | |
708 | fi | | |
cf7bb589 | 709 | git-stripspace >"$GIT_DIR"/COMMIT_MSG |
f8e2c54c SB |
710 | |
711 | if cnt=`grep -v -i '^Signed-off-by' "$GIT_DIR"/COMMIT_MSG | | |
712 | git-stripspace | | |
713 | wc -l` && | |
714 | test 0 -lt $cnt | |
0c091296 | 715 | then |
130fcca6 JH |
716 | if test -z "$TMP_INDEX" |
717 | then | |
cf7bb589 | 718 | tree=$(GIT_INDEX_FILE="$USE_INDEX" git-write-tree) |
130fcca6 JH |
719 | else |
720 | tree=$(GIT_INDEX_FILE="$TMP_INDEX" git-write-tree) && | |
721 | rm -f "$TMP_INDEX" | |
722 | fi && | |
f8e2c54c | 723 | commit=$(cat "$GIT_DIR"/COMMIT_MSG | git-commit-tree $tree $PARENTS) && |
67644a4d | 724 | rlogm=$(sed -e 1q "$GIT_DIR"/COMMIT_MSG) && |
a3a733e6 | 725 | git-update-ref -m "$rloga: $rlogm" HEAD $commit $current && |
cf7bb589 JH |
726 | rm -f -- "$GIT_DIR/MERGE_HEAD" && |
727 | if test -f "$NEXT_INDEX" | |
728 | then | |
729 | mv "$NEXT_INDEX" "$THIS_INDEX" | |
730 | else | |
731 | : ;# happy | |
732 | fi | |
0c091296 JH |
733 | else |
734 | echo >&2 "* no commit message? aborting commit." | |
735 | false | |
736 | fi | |
170241b7 | 737 | ret="$?" |
7d0c6887 | 738 | rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG" |
1536dd9c JH |
739 | if test -d "$GIT_DIR/rr-cache" |
740 | then | |
741 | git-rerere | |
742 | fi | |
89e2c5f1 JH |
743 | |
744 | if test -x "$GIT_DIR"/hooks/post-commit && test "$ret" = 0 | |
745 | then | |
746 | "$GIT_DIR"/hooks/post-commit | |
747 | fi | |
170241b7 | 748 | exit "$ret" |