Imported Upstream version 2.17.5
[platform/upstream/git.git] / t / t4041-diff-submodule-option.sh
index 32d4a60..058ee08 100755 (executable)
@@ -1,6 +1,7 @@
 #!/bin/sh
 #
 # Copyright (c) 2009 Jens Lehmann, based on t7401 by Ping Yin
+# Copyright (c) 2011 Alexey Shumkin (+ non-UTF-8 commit encoding tests)
 #
 
 test_description='Support for verbose submodule differences in git diff
@@ -10,6 +11,12 @@ This test tries to verify the sanity of the --submodule option of git diff.
 
 . ./test-lib.sh
 
+# Tested non-UTF-8 encoding
+test_encoding="ISO8859-1"
+
+# String "added" in German (translated with Google Translate), encoded in UTF-8,
+# used in sample commit log messages in add_file() function below.
+added=$(printf "hinzugef\303\274gt")
 add_file () {
        (
                cd "$1" &&
@@ -19,7 +26,10 @@ add_file () {
                        echo "$name" >"$name" &&
                        git add "$name" &&
                        test_tick &&
-                       git commit -m "Add $name" || exit
+                       # "git commit -m" would break MinGW, as Windows refuse to pass
+                       # $test_encoding encoded parameter to git.
+                       echo "Add $name ($added $name)" | iconv -f utf-8 -t $test_encoding |
+                       git -c "i18n.commitEncoding=$test_encoding" commit -F -
                done >/dev/null &&
                git rev-parse --short --verify HEAD
        )
@@ -93,7 +103,7 @@ test_expect_success 'modified submodule(forward)' '
        git diff-index -p --submodule=log HEAD >actual &&
        cat >expected <<-EOF &&
        Submodule sm1 $head1..$head2:
-         > Add foo3
+         > Add foo3 ($added foo3)
        EOF
        test_cmp expected actual
 '
@@ -102,7 +112,7 @@ test_expect_success 'modified submodule(forward)' '
        git diff --submodule=log >actual &&
        cat >expected <<-EOF &&
        Submodule sm1 $head1..$head2:
-         > Add foo3
+         > Add foo3 ($added foo3)
        EOF
        test_cmp expected actual
 '
@@ -111,7 +121,7 @@ test_expect_success 'modified submodule(forward) --submodule' '
        git diff --submodule >actual &&
        cat >expected <<-EOF &&
        Submodule sm1 $head1..$head2:
-         > Add foo3
+         > Add foo3 ($added foo3)
        EOF
        test_cmp expected actual
 '
@@ -142,8 +152,8 @@ test_expect_success 'modified submodule(backward)' '
        git diff-index -p --submodule=log HEAD >actual &&
        cat >expected <<-EOF &&
        Submodule sm1 $head2..$head3 (rewind):
-         < Add foo3
-         < Add foo2
+         < Add foo3 ($added foo3)
+         < Add foo2 ($added foo2)
        EOF
        test_cmp expected actual
 '
@@ -153,10 +163,10 @@ test_expect_success 'modified submodule(backward and forward)' '
        git diff-index -p --submodule=log HEAD >actual &&
        cat >expected <<-EOF &&
        Submodule sm1 $head2...$head4:
-         > Add foo5
-         > Add foo4
-         < Add foo3
-         < Add foo2
+         > Add foo5 ($added foo5)
+         > Add foo4 ($added foo4)
+         < Add foo3 ($added foo3)
+         < Add foo2 ($added foo2)
        EOF
        test_cmp expected actual
 '
@@ -420,9 +430,11 @@ test_expect_success 'deleted submodule' '
        test_cmp expected actual
 '
 
-test_create_repo sm2 &&
-head7=$(add_file sm2 foo8 foo9) &&
-git add sm2
+test_expect_success 'create second submodule' '
+       test_create_repo sm2 &&
+       head7=$(add_file sm2 foo8 foo9) &&
+       git add sm2
+'
 
 test_expect_success 'multiple submodules' '
        git diff-index -p --submodule=log HEAD >actual &&
@@ -518,10 +530,12 @@ test_expect_success 'diff --submodule with objects referenced by alternates' '
                sha1_before=$(git rev-parse --short HEAD)
                echo b >b &&
                git add b &&
-               git commit -m b
-               sha1_after=$(git rev-parse --short HEAD)
-               echo "Submodule sub $sha1_before..$sha1_after:
-  > b" >../expected
+               git commit -m b &&
+               sha1_after=$(git rev-parse --short HEAD) &&
+               {
+                       echo "Submodule sub $sha1_before..$sha1_after:" &&
+                       echo "  > b"
+               } >../expected
        ) &&
        (cd super &&
                (cd sub &&
@@ -529,7 +543,7 @@ test_expect_success 'diff --submodule with objects referenced by alternates' '
                        git checkout origin/master
                ) &&
                git diff --submodule > ../actual
-       )
+       ) &&
        test_cmp expected actual
 '