config: work around bug with includeif:onbranch and early config
[gitweb.git] / t / t7411-submodule-config.sh
index 45953f93007257c9b1d9799b51d555941ecad082..ad28e9388053c4009f4af3121788951f9e79d848 100755 (executable)
@@ -134,7 +134,7 @@ test_expect_success 'error in history in fetchrecursesubmodule lets continue' '
        )
 '
 
-test_expect_success 'reading submodules config with "submodule--helper config"' '
+test_expect_success 'reading submodules config from the working tree with "submodule--helper config"' '
        (cd super &&
                echo "../submodule" >expect &&
                git submodule--helper config submodule.submodule.url >actual &&
@@ -142,6 +142,15 @@ test_expect_success 'reading submodules config with "submodule--helper config"'
        )
 '
 
+test_expect_success 'unsetting submodules config from the working tree with "submodule--helper config --unset"' '
+       (cd super &&
+               git submodule--helper config --unset submodule.submodule.url &&
+               git submodule--helper config submodule.submodule.url >actual &&
+               test_must_be_empty actual
+       )
+'
+
+
 test_expect_success 'writing submodules config with "submodule--helper config"' '
        (cd super &&
                echo "new_url" >expect &&
@@ -192,4 +201,58 @@ test_expect_success 'non-writeable .gitmodules when it is in the current branch
        )
 '
 
+test_expect_success 'reading submodules config from the index when .gitmodules is not in the working tree' '
+       ORIG=$(git -C super rev-parse HEAD) &&
+       test_when_finished "git -C super reset --hard $ORIG" &&
+       (cd super &&
+               git submodule--helper config submodule.submodule.url "staged_url" &&
+               git add .gitmodules &&
+               rm -f .gitmodules &&
+               echo "staged_url" >expect &&
+               git submodule--helper config submodule.submodule.url >actual &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success 'reading submodules config from the current branch when .gitmodules is not in the index' '
+       ORIG=$(git -C super rev-parse HEAD) &&
+       test_when_finished "git -C super reset --hard $ORIG" &&
+       (cd super &&
+               git rm .gitmodules &&
+               echo "../submodule" >expect &&
+               git submodule--helper config submodule.submodule.url >actual &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success 'reading nested submodules config' '
+       (cd super &&
+               git init submodule/nested_submodule &&
+               echo "a" >submodule/nested_submodule/a &&
+               git -C submodule/nested_submodule add a &&
+               git -C submodule/nested_submodule commit -m "add a" &&
+               git -C submodule submodule add ./nested_submodule &&
+               git -C submodule add nested_submodule &&
+               git -C submodule commit -m "added nested_submodule" &&
+               git add submodule &&
+               git commit -m "updated submodule" &&
+               echo "./nested_submodule" >expect &&
+               test-tool submodule-nested-repo-config \
+                       submodule submodule.nested_submodule.url >actual &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success 'reading nested submodules config when .gitmodules is not in the working tree' '
+       test_when_finished "git -C super/submodule checkout .gitmodules" &&
+       (cd super &&
+               echo "./nested_submodule" >expect &&
+               rm submodule/.gitmodules &&
+               test-tool submodule-nested-repo-config \
+                       submodule submodule.nested_submodule.url >actual 2>warning &&
+               test_must_be_empty warning &&
+               test_cmp expect actual
+       )
+'
+
 test_done