Imported Upstream version 2.17.5
[platform/upstream/git.git] / t / t7501-commit.sh
index b20ca0e..fa61b1a 100755 (executable)
@@ -18,7 +18,7 @@ test_expect_success 'initial status' '
        echo bongo bongo >file &&
        git add file &&
        git status >actual &&
-       test_i18ngrep "Initial commit" actual
+       test_i18ngrep "No commits yet" actual
 '
 
 test_expect_success 'fail initial amend' '
@@ -53,18 +53,55 @@ test_expect_success PERL 'can use paths with --interactive' '
 '
 
 test_expect_success 'using invalid commit with -C' '
-       test_must_fail git commit -C bogus
+       test_must_fail git commit --allow-empty -C bogus
 '
 
 test_expect_success 'nothing to commit' '
+       git reset --hard &&
        test_must_fail git commit -m initial
 '
 
+test_expect_success '--dry-run fails with nothing to commit' '
+       test_must_fail git commit -m initial --dry-run
+'
+
+test_expect_success '--short fails with nothing to commit' '
+       test_must_fail git commit -m initial --short
+'
+
+test_expect_success '--porcelain fails with nothing to commit' '
+       test_must_fail git commit -m initial --porcelain
+'
+
+test_expect_success '--long fails with nothing to commit' '
+       test_must_fail git commit -m initial --long
+'
+
 test_expect_success 'setup: non-initial commit' '
        echo bongo bongo bongo >file &&
        git commit -m next -a
 '
 
+test_expect_success '--dry-run with stuff to commit returns ok' '
+       echo bongo bongo bongo >>file &&
+       git commit -m next -a --dry-run
+'
+
+test_expect_failure '--short with stuff to commit returns ok' '
+       echo bongo bongo bongo >>file &&
+       git commit -m next -a --short
+'
+
+test_expect_failure '--porcelain with stuff to commit returns ok' '
+       echo bongo bongo bongo >>file &&
+       git commit -m next -a --porcelain
+'
+
+test_expect_success '--long with stuff to commit returns ok' '
+       echo bongo bongo bongo >>file &&
+       git commit -m next -a --long
+'
+
 test_expect_success 'commit message from non-existing file' '
        echo more bongo: bongo bongo bongo bongo >file &&
        test_must_fail git commit -F gah -a
@@ -108,6 +145,25 @@ test_expect_success 'amend commit' '
        EDITOR=./editor git commit --amend
 '
 
+test_expect_success 'amend --only ignores staged contents' '
+       cp file file.expect &&
+       echo changed >file &&
+       git add file &&
+       git commit --no-edit --amend --only &&
+       git cat-file blob HEAD:file >file.actual &&
+       test_cmp file.expect file.actual &&
+       git diff --exit-code
+'
+
+test_expect_success 'allow-empty --only ignores staged contents' '
+       echo changed-again >file &&
+       git add file &&
+       git commit --allow-empty --only -m "empty" &&
+       git cat-file blob HEAD:file >file.actual &&
+       test_cmp file.expect file.actual &&
+       git diff --exit-code
+'
+
 test_expect_success 'set up editor' '
        cat >editor <<-\EOF &&
        #!/bin/sh
@@ -138,6 +194,41 @@ test_expect_success '--amend --edit' '
        test_cmp expect msg
 '
 
+test_expect_success '--amend --edit of empty message' '
+       cat >replace <<-\EOF &&
+       #!/bin/sh
+       echo "amended" >"$1"
+       EOF
+       chmod 755 replace &&
+       git commit --allow-empty --allow-empty-message -m "" &&
+       echo more bongo >file &&
+       git add file &&
+       EDITOR=./replace git commit --edit --amend &&
+       git diff-tree -s --format=%s HEAD >msg &&
+       ./replace expect &&
+       test_cmp expect msg
+'
+
+test_expect_success '--amend to set message to empty' '
+       echo bata >file &&
+       git add file &&
+       git commit -m "unamended" &&
+       git commit --amend --allow-empty-message -m "" &&
+       git diff-tree -s --format=%s HEAD >msg &&
+       echo "" >expect &&
+       test_cmp expect msg
+'
+
+test_expect_success '--amend to set empty message needs --allow-empty-message' '
+       echo conga >file &&
+       git add file &&
+       git commit -m "unamended" &&
+       test_must_fail git commit --amend -m "" &&
+       git diff-tree -s --format=%s HEAD >msg &&
+       echo "unamended" >expect &&
+       test_cmp expect msg
+'
+
 test_expect_success '-m --edit' '
        echo amended >expect &&
        git commit --allow-empty -m buffer &&
@@ -284,8 +375,21 @@ test_expect_success 'amend commit to fix date' '
 
 '
 
-test_expect_success 'commit complains about bogus date' '
-       test_must_fail git commit --amend --date=10.11.2010
+test_expect_success 'commit mentions forced date in output' '
+       git commit --amend --date=2010-01-02T03:04:05 >output &&
+       grep "Date: *Sat Jan 2 03:04:05 2010" output
+'
+
+test_expect_success 'commit complains about completely bogus dates' '
+       test_must_fail git commit --amend --date=seventeen
+'
+
+test_expect_success 'commit --date allows approxidate' '
+       git commit --amend \
+               --date="midnight the 12th of october, anno domini 1979" &&
+       echo "Fri Oct 12 00:00:00 1979 +0000" >expect &&
+       git log -1 --format=%ad >actual &&
+       test_cmp expect actual
 '
 
 test_expect_success 'sign off (1)' '
@@ -365,6 +469,42 @@ $alt" &&
        test_cmp expected actual
 '
 
+test_expect_success 'signoff respects trailer config' '
+
+       echo 5 >positive &&
+       git add positive &&
+       git commit -s -m "subject
+
+non-trailer line
+Myfooter: x" &&
+       git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
+       (
+               echo subject
+               echo
+               echo non-trailer line
+               echo Myfooter: x
+               echo
+               echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
+       ) >expected &&
+       test_cmp expected actual &&
+
+       echo 6 >positive &&
+       git add positive &&
+       git -c "trailer.Myfooter.ifexists=add" commit -s -m "subject
+
+non-trailer line
+Myfooter: x" &&
+       git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
+       (
+               echo subject
+               echo
+               echo non-trailer line
+               echo Myfooter: x
+               echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
+       ) >expected &&
+       test_cmp expected actual
+'
+
 test_expect_success 'multiple -m' '
 
        >negative &&
@@ -487,4 +627,49 @@ test_expect_success 'amend can copy notes' '
 
 '
 
+test_expect_success 'commit a file whose name is a dash' '
+       git reset --hard &&
+       for i in 1 2 3 4 5
+       do
+               echo $i
+       done >./- &&
+       git add ./- &&
+       test_tick &&
+       git commit -m "add dash" >output </dev/null &&
+       test_i18ngrep " changed, 5 insertions" output
+'
+
+test_expect_success '--only works on to-be-born branch' '
+       # This test relies on having something in the index, as it
+       # would not otherwise actually prove much.  So check this.
+       test -n "$(git ls-files)" &&
+       git checkout --orphan orphan &&
+       echo foo >newfile &&
+       git add newfile &&
+       git commit --only newfile -m"--only on unborn branch" &&
+       echo newfile >expected &&
+       git ls-tree -r --name-only HEAD >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success '--dry-run with conflicts fixed from a merge' '
+       # setup two branches with conflicting information
+       # in the same file, resolve the conflict,
+       # call commit with --dry-run
+       echo "Initial contents, unimportant" >test-file &&
+       git add test-file &&
+       git commit -m "Initial commit" &&
+       echo "commit-1-state" >test-file &&
+       git commit -m "commit 1" -i test-file &&
+       git tag commit-1 &&
+       git checkout -b branch-2 HEAD^1 &&
+       echo "commit-2-state" >test-file &&
+       git commit -m "commit 2" -i test-file &&
+       ! $(git merge --no-commit commit-1) &&
+       echo "commit-2-state" >test-file &&
+       git add test-file &&
+       git commit --dry-run &&
+       git commit -m "conflicts fixed from merge."
+'
+
 test_done