~ubuntu-branches/ubuntu/intrepid/git-core/intrepid-updates

« back to all changes in this revision

Viewing changes to git-commit.sh

  • Committer: Package Import Robot
  • Author(s): Gerrit Pape
  • Date: 2007-04-22 13:31:05 UTC
  • mfrom: (1.1.14)
  • Revision ID: package-import@ubuntu.com-20070422133105-tkmhz328g2p0epz1
Tags: 1:1.5.1.2-1
* new upstream point release.
* debian/changelog.upstream: upstream changes taken from mailing list
  announcement.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
# Copyright (c) 2005 Linus Torvalds
4
4
# Copyright (c) 2006 Junio C Hamano
5
5
 
6
 
USAGE='[-a] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit>] [-u] [--amend] [-e] [--author <author>] [[-i | -o] <path>...]'
 
6
USAGE='[-a | --interactive] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit> | --amend] [-u] [-e] [--author <author>] [[-i | -o] <path>...]'
7
7
SUBDIRECTORY_OK=Yes
8
8
. git-sh-setup
 
9
require_work_tree
9
10
 
10
11
git-rev-parse --verify HEAD >/dev/null 2>&1 || initial_commit=t
11
 
branch=$(GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD)
12
12
 
13
13
case "$0" in
14
14
*status)
15
15
        status_only=t
16
 
        unmerged_ok_if_status=--unmerged ;;
 
16
        ;;
17
17
*commit)
18
18
        status_only=
19
 
        unmerged_ok_if_status= ;;
 
19
        ;;
20
20
esac
21
21
 
22
22
refuse_partial () {
71
71
 
72
72
all=
73
73
also=
 
74
interactive=
74
75
only=
75
76
logfile=
76
77
use_commit=
80
81
log_given=
81
82
log_message=
82
83
verify=t
 
84
quiet=
83
85
verbose=
84
86
signoff=
85
87
force_author=
130
132
                also=t
131
133
                shift
132
134
                ;;
 
135
        --int|--inte|--inter|--intera|--interac|--interact|--interacti|\
 
136
        --interactiv|--interactive)
 
137
                interactive=t
 
138
                shift
 
139
                ;;
133
140
        -o|--o|--on|--onl|--only)
134
141
                only=t
135
142
                shift
241
248
                signoff=t
242
249
                shift
243
250
                ;;
 
251
        -q|--q|--qu|--qui|--quie|--quiet)
 
252
                quiet=t
 
253
                shift
 
254
                ;;
244
255
        -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
245
256
                verbose=t
246
257
                shift
279
290
 
280
291
case "$log_given" in
281
292
tt*)
282
 
        die "Only one of -c/-C/-F can be used." ;;
 
293
        die "Only one of -c/-C/-F/--amend can be used." ;;
283
294
*tm*|*mt*)
284
 
        die "Option -m cannot be combined with -c/-C/-F." ;;
 
295
        die "Option -m cannot be combined with -c/-C/-F/--amend." ;;
285
296
esac
286
297
 
287
298
case "$#,$also,$only,$amend" in
299
310
        ;;
300
311
esac
301
312
unset only
302
 
case "$all,$also,$#" in
303
 
t,t,*)
304
 
        die "Cannot use -a and -i at the same time." ;;
 
313
case "$all,$interactive,$also,$#" in
 
314
*t,*t,*)
 
315
        die "Cannot use -a, --interactive or -i at the same time." ;;
305
316
t,,[1-9]*)
306
317
        die "Paths with -a does not make sense." ;;
307
 
,t,0)
 
318
,t,[1-9]*)
 
319
        die "Paths with --interactive does not make sense." ;;
 
320
,,t,0)
308
321
        die "No paths with -i does not make sense." ;;
309
322
esac
310
323
 
311
324
################################################################
312
325
# Prepare index to have a tree to be committed
313
326
 
314
 
TOP=`git-rev-parse --show-cdup`
315
 
if test -z "$TOP"
316
 
then
317
 
        TOP=./
318
 
fi
319
 
 
320
327
case "$all,$also" in
321
328
t,)
 
329
        if test ! -f "$THIS_INDEX"
 
330
        then
 
331
                die 'nothing to commit (use "git add file1 file2" to include for commit)'
 
332
        fi
322
333
        save_index &&
323
334
        (
324
 
                cd "$TOP"
325
 
                GIT_INDEX_FILE="$NEXT_INDEX"
326
 
                export GIT_INDEX_FILE
 
335
                cd_to_toplevel &&
 
336
                GIT_INDEX_FILE="$NEXT_INDEX" &&
 
337
                export GIT_INDEX_FILE &&
327
338
                git-diff-files --name-only -z |
328
339
                git-update-index --remove -z --stdin
329
 
        )
 
340
        ) || exit
330
341
        ;;
331
342
,t)
332
343
        save_index &&
334
345
 
335
346
        git-diff-files --name-only -z -- "$@"  |
336
347
        (
337
 
                cd "$TOP"
338
 
                GIT_INDEX_FILE="$NEXT_INDEX"
339
 
                export GIT_INDEX_FILE
 
348
                cd_to_toplevel &&
 
349
                GIT_INDEX_FILE="$NEXT_INDEX" &&
 
350
                export GIT_INDEX_FILE &&
340
351
                git-update-index --remove -z --stdin
341
 
        )
 
352
        ) || exit
342
353
        ;;
343
354
,)
 
355
        if test "$interactive" = t; then
 
356
                git add --interactive || exit
 
357
        fi
344
358
        case "$#" in
345
359
        0)
346
360
                ;; # commit as-is
350
364
                        refuse_partial "Cannot do a partial commit during a merge."
351
365
                fi
352
366
                TMP_INDEX="$GIT_DIR/tmp-index$$"
353
 
                if test -z "$initial_commit"
354
 
                then
355
 
                        # make sure index is clean at the specified paths, or
356
 
                        # they are additions.
357
 
                        dirty_in_index=`git-diff-index --cached --name-status \
358
 
                                --diff-filter=DMTU HEAD -- "$@"`
359
 
                        test -z "$dirty_in_index" ||
360
 
                        refuse_partial "Different in index and the last commit:
361
 
$dirty_in_index"
362
 
                fi
363
367
                commit_only=`git-ls-files --error-unmatch -- "$@"` || exit
364
368
 
365
 
                # Build the temporary index and update the real index
 
369
                # Build a temporary index and update the real index
366
370
                # the same way.
367
371
                if test -z "$initial_commit"
368
372
                then
369
373
                        cp "$THIS_INDEX" "$TMP_INDEX"
370
 
                        GIT_INDEX_FILE="$TMP_INDEX" git-read-tree -m HEAD
 
374
                        GIT_INDEX_FILE="$TMP_INDEX" git-read-tree -i -m HEAD
371
375
                else
372
376
                        rm -f "$TMP_INDEX"
373
377
                fi || exit
400
404
        USE_INDEX="$THIS_INDEX"
401
405
fi
402
406
 
403
 
GIT_INDEX_FILE="$USE_INDEX" \
404
 
        git-update-index -q $unmerged_ok_if_status --refresh || exit
405
 
 
406
 
################################################################
407
 
# If the request is status, just show it and exit.
408
 
 
409
 
case "$0" in
410
 
*status)
 
407
case "$status_only" in
 
408
t)
 
409
        # This will silently fail in a read-only repository, which is
 
410
        # what we want.
 
411
        GIT_INDEX_FILE="$USE_INDEX" git-update-index -q --unmerged --refresh
411
412
        run_status
412
413
        exit $?
 
414
        ;;
 
415
'')
 
416
        GIT_INDEX_FILE="$USE_INDEX" git-update-index -q --refresh || exit
 
417
        ;;
413
418
esac
414
419
 
415
420
################################################################
440
445
        fi
441
446
elif test "$use_commit" != ""
442
447
then
443
 
        git-cat-file commit "$use_commit" | sed -e '1,/^$/d'
 
448
        encoding=$(git config i18n.commitencoding || echo UTF-8)
 
449
        git show -s --pretty=raw --encoding="$encoding" "$use_commit" |
 
450
        sed -e '1,/^$/d' -e 's/^    //'
444
451
elif test -f "$GIT_DIR/MERGE_MSG"
445
452
then
446
453
        cat "$GIT_DIR/MERGE_MSG"
451
458
 
452
459
case "$signoff" in
453
460
t)
 
461
        need_blank_before_signoff=
 
462
        tail -n 1 "$GIT_DIR"/COMMIT_EDITMSG |
 
463
        grep 'Signed-off-by:' >/dev/null || need_blank_before_signoff=yes
454
464
        {
455
 
                echo
 
465
                test -z "$need_blank_before_signoff" || echo
456
466
                git-var GIT_COMMITTER_IDENT | sed -e '
457
467
                        s/>.*/>/
458
468
                        s/^/Signed-off-by: /
471
481
fi >>"$GIT_DIR"/COMMIT_EDITMSG
472
482
 
473
483
# Author
474
 
if test '' != "$force_author"
475
 
then
476
 
        GIT_AUTHOR_NAME=`expr "z$force_author" : 'z\(.*[^ ]\) *<.*'` &&
477
 
        GIT_AUTHOR_EMAIL=`expr "z$force_author" : '.*\(<.*\)'` &&
478
 
        test '' != "$GIT_AUTHOR_NAME" &&
479
 
        test '' != "$GIT_AUTHOR_EMAIL" ||
480
 
        die "malformed --author parameter"
481
 
        export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
482
 
elif test '' != "$use_commit"
 
484
if test '' != "$use_commit"
483
485
then
484
486
        pick_author_script='
485
487
        /^author /{
502
504
                q
503
505
        }
504
506
        '
505
 
        set_author_env=`git-cat-file commit "$use_commit" |
 
507
        encoding=$(git config i18n.commitencoding || echo UTF-8)
 
508
        set_author_env=`git show -s --pretty=raw --encoding="$encoding" "$use_commit" |
506
509
        LANG=C LC_ALL=C sed -ne "$pick_author_script"`
507
510
        eval "$set_author_env"
508
511
        export GIT_AUTHOR_NAME
509
512
        export GIT_AUTHOR_EMAIL
510
513
        export GIT_AUTHOR_DATE
511
514
fi
 
515
if test '' != "$force_author"
 
516
then
 
517
        GIT_AUTHOR_NAME=`expr "z$force_author" : 'z\(.*[^ ]\) *<.*'` &&
 
518
        GIT_AUTHOR_EMAIL=`expr "z$force_author" : '.*\(<.*\)'` &&
 
519
        test '' != "$GIT_AUTHOR_NAME" &&
 
520
        test '' != "$GIT_AUTHOR_EMAIL" ||
 
521
        die "malformed --author parameter"
 
522
        export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
 
523
fi
512
524
 
513
525
PARENTS="-p HEAD"
514
526
if test -z "$initial_commit"
525
537
        current="$(git-rev-parse --verify HEAD)"
526
538
else
527
539
        if [ -z "$(git-ls-files)" ]; then
528
 
                echo >&2 Nothing to commit
 
540
                echo >&2 'nothing to commit (use "git add file1 file2" to include for commit)'
529
541
                exit 1
530
542
        fi
531
543
        PARENTS=""
532
544
        rloga='commit (initial)'
533
545
        current=''
534
546
fi
 
547
set_reflog_action "$rloga"
535
548
 
536
549
if test -z "$no_edit"
537
550
then
606
619
        fi &&
607
620
        commit=$(cat "$GIT_DIR"/COMMIT_MSG | git-commit-tree $tree $PARENTS) &&
608
621
        rlogm=$(sed -e 1q "$GIT_DIR"/COMMIT_MSG) &&
609
 
        git-update-ref -m "$rloga: $rlogm" HEAD $commit "$current" &&
 
622
        git-update-ref -m "$GIT_REFLOG_ACTION: $rlogm" HEAD $commit "$current" &&
610
623
        rm -f -- "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/MERGE_MSG" &&
611
624
        if test -f "$NEXT_INDEX"
612
625
        then
620
633
fi
621
634
ret="$?"
622
635
rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG"
 
636
 
 
637
cd_to_toplevel
 
638
 
623
639
if test -d "$GIT_DIR/rr-cache"
624
640
then
625
641
        git-rerere
626
642
fi
627
643
 
628
 
if test -x "$GIT_DIR"/hooks/post-commit && test "$ret" = 0
 
644
if test "$ret" = 0
629
645
then
630
 
        "$GIT_DIR"/hooks/post-commit
 
646
        if test -x "$GIT_DIR"/hooks/post-commit
 
647
        then
 
648
                "$GIT_DIR"/hooks/post-commit
 
649
        fi
 
650
        if test -z "$quiet"
 
651
        then
 
652
                echo "Created${initial_commit:+ initial} commit $commit"
 
653
                git-diff-tree --shortstat --summary --root --no-commit-id HEAD --
 
654
        fi
631
655
fi
 
656
 
632
657
exit "$ret"