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