test-lib: parse options in a for loop to keep $@ intact
[gitweb.git] / t / t4027-diff-submodule.sh
index 83c19147717f2a5e6c634918c74b93e54376d725..9aa8e2b39b45a6c2b5ec48a9d98b94831edb2caa 100755 (executable)
@@ -5,7 +5,6 @@ test_description='difference in submodules'
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/diff-lib.sh
 
-_z40=0000000000000000000000000000000000000000
 test_expect_success setup '
        test_tick &&
        test_create_repo sub &&
@@ -32,7 +31,7 @@ test_expect_success setup '
                cd sub &&
                git rev-list HEAD
        ) &&
-       echo ":160000 160000 $3 $_z40 M sub" >expect &&
+       echo ":160000 160000 $3 $ZERO_OID M     sub" >expect &&
        subtip=$3 subprev=$2
 '
 
@@ -103,7 +102,49 @@ test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match)'
        git diff HEAD >actual &&
        sed -e "1,/^@@/d" actual >actual.body &&
        expect_from_to >expect.body $subprev $subprev-dirty &&
-       test_cmp expect.body actual.body
+       test_cmp expect.body actual.body &&
+       git diff --ignore-submodules HEAD >actual2 &&
+       test_must_be_empty actual2 &&
+       git diff --ignore-submodules=untracked HEAD >actual3 &&
+       sed -e "1,/^@@/d" actual3 >actual3.body &&
+       expect_from_to >expect.body $subprev $subprev-dirty &&
+       test_cmp expect.body actual3.body &&
+       git diff --ignore-submodules=dirty HEAD >actual4 &&
+       test_must_be_empty actual4
+'
+
+test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match) [.gitmodules]' '
+       git config diff.ignoreSubmodules dirty &&
+       git diff HEAD >actual &&
+       test_must_be_empty actual &&
+       git config --add -f .gitmodules submodule.subname.ignore none &&
+       git config --add -f .gitmodules submodule.subname.path sub &&
+       git diff HEAD >actual &&
+       sed -e "1,/^@@/d" actual >actual.body &&
+       expect_from_to >expect.body $subprev $subprev-dirty &&
+       test_cmp expect.body actual.body &&
+       git config -f .gitmodules submodule.subname.ignore all &&
+       git config -f .gitmodules submodule.subname.path sub &&
+       git diff HEAD >actual2 &&
+       test_must_be_empty actual2 &&
+       git config -f .gitmodules submodule.subname.ignore untracked &&
+       git diff HEAD >actual3 &&
+       sed -e "1,/^@@/d" actual3 >actual3.body &&
+       expect_from_to >expect.body $subprev $subprev-dirty &&
+       test_cmp expect.body actual3.body &&
+       git config -f .gitmodules submodule.subname.ignore dirty &&
+       git diff HEAD >actual4 &&
+       test_must_be_empty actual4 &&
+       git config submodule.subname.ignore none &&
+       git config submodule.subname.path sub &&
+       git diff HEAD >actual &&
+       sed -e "1,/^@@/d" actual >actual.body &&
+       expect_from_to >expect.body $subprev $subprev-dirty &&
+       test_cmp expect.body actual.body &&
+       git config --remove-section submodule.subname &&
+       git config --remove-section -f .gitmodules submodule.subname &&
+       git config --unset diff.ignoreSubmodules &&
+       rm .gitmodules
 '
 
 test_expect_success 'git diff HEAD with dirty submodule (index, refs match)' '
@@ -129,24 +170,88 @@ test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)'
        git diff HEAD >actual &&
        sed -e "1,/^@@/d" actual >actual.body &&
        expect_from_to >expect.body $subprev $subprev-dirty &&
-       test_cmp expect.body actual.body
+       test_cmp expect.body actual.body &&
+       git diff --ignore-submodules=all HEAD >actual2 &&
+       test_must_be_empty actual2 &&
+       git diff --ignore-submodules=untracked HEAD >actual3 &&
+       test_must_be_empty actual3 &&
+       git diff --ignore-submodules=dirty HEAD >actual4 &&
+       test_must_be_empty actual4
+'
+
+test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match) [.gitmodules]' '
+       git config --add -f .gitmodules submodule.subname.ignore all &&
+       git config --add -f .gitmodules submodule.subname.path sub &&
+       git diff HEAD >actual2 &&
+       test_must_be_empty actual2 &&
+       git config -f .gitmodules submodule.subname.ignore untracked &&
+       git diff HEAD >actual3 &&
+       test_must_be_empty actual3 &&
+       git config -f .gitmodules submodule.subname.ignore dirty &&
+       git diff HEAD >actual4 &&
+       test_must_be_empty actual4 &&
+       git config submodule.subname.ignore none &&
+       git config submodule.subname.path sub &&
+       git diff HEAD >actual &&
+       sed -e "1,/^@@/d" actual >actual.body &&
+       expect_from_to >expect.body $subprev $subprev-dirty &&
+       test_cmp expect.body actual.body &&
+       git config --remove-section submodule.subname &&
+       git config --remove-section -f .gitmodules submodule.subname &&
+       rm .gitmodules
+'
+
+test_expect_success 'git diff between submodule commits' '
+       git diff HEAD^..HEAD >actual &&
+       sed -e "1,/^@@/d" actual >actual.body &&
+       expect_from_to >expect.body $subtip $subprev &&
+       test_cmp expect.body actual.body &&
+       git diff --ignore-submodules=dirty HEAD^..HEAD >actual &&
+       sed -e "1,/^@@/d" actual >actual.body &&
+       expect_from_to >expect.body $subtip $subprev &&
+       test_cmp expect.body actual.body &&
+       git diff --ignore-submodules HEAD^..HEAD >actual &&
+       test_must_be_empty actual
+'
+
+test_expect_success 'git diff between submodule commits [.gitmodules]' '
+       git diff HEAD^..HEAD >actual &&
+       sed -e "1,/^@@/d" actual >actual.body &&
+       expect_from_to >expect.body $subtip $subprev &&
+       test_cmp expect.body actual.body &&
+       git config --add -f .gitmodules submodule.subname.ignore dirty &&
+       git config --add -f .gitmodules submodule.subname.path sub &&
+       git diff HEAD^..HEAD >actual &&
+       sed -e "1,/^@@/d" actual >actual.body &&
+       expect_from_to >expect.body $subtip $subprev &&
+       test_cmp expect.body actual.body &&
+       git config -f .gitmodules submodule.subname.ignore all &&
+       git diff HEAD^..HEAD >actual &&
+       test_must_be_empty actual &&
+       git config submodule.subname.ignore dirty &&
+       git config submodule.subname.path sub &&
+       git diff  HEAD^..HEAD >actual &&
+       sed -e "1,/^@@/d" actual >actual.body &&
+       expect_from_to >expect.body $subtip $subprev &&
+       git config --remove-section submodule.subname &&
+       git config --remove-section -f .gitmodules submodule.subname &&
+       rm .gitmodules
 '
 
 test_expect_success 'git diff (empty submodule dir)' '
-       : >empty &&
        rm -rf sub/* sub/.git &&
        git diff > actual.empty &&
-       test_cmp empty actual.empty
+       test_must_be_empty actual.empty
 '
 
 test_expect_success 'conflicted submodule setup' '
 
        # 39 efs
-       c=fffffffffffffffffffffffffffffffffffffff
+       c=fffffffffffffffffffffffffffffffffffffff &&
        (
-               echo "000000 $_z40 0    sub"
-               echo "160000 1$c 1      sub"
-               echo "160000 2$c 2      sub"
+               echo "000000 $ZERO_OID 0        sub" &&
+               echo "160000 1$c 1      sub" &&
+               echo "160000 2$c 2      sub" &&
                echo "160000 3$c 3      sub"
        ) | git update-index --index-info &&
        echo >expect.nosub '\''diff --cc sub
@@ -159,7 +264,7 @@ index 2ffffff,3ffffff..0000000
 ++Subproject commit 0000000000000000000000000000000000000000'\'' &&
 
        hh=$(git rev-parse HEAD) &&
-       sed -e "s/$_z40/$hh/" expect.nosub >expect.withsub
+       sed -e "s/$ZERO_OID/$hh/" expect.nosub >expect.withsub
 
 '