config: work around bug with includeif:onbranch and early config
[gitweb.git] / t / t7411-submodule-config.sh
index f2cd1f4a2c540beb8c71e79641ac7a7fd2de7f14..ad28e9388053c4009f4af3121788951f9e79d848 100755 (executable)
@@ -83,6 +83,8 @@ Submodule name: 'submodule' for path 'submodule'
 EOF
 
 test_expect_success 'error in history of one submodule config lets continue, stderr message contains blob ref' '
+       ORIG=$(git -C super rev-parse HEAD) &&
+       test_when_finished "git -C super reset --hard $ORIG" &&
        (cd super &&
                cp .gitmodules .gitmodules.bak &&
                echo "  value = \"" >>.gitmodules &&
@@ -115,6 +117,8 @@ test_expect_success 'using different treeishs works' '
 '
 
 test_expect_success 'error in history in fetchrecursesubmodule lets continue' '
+       ORIG=$(git -C super rev-parse HEAD) &&
+       test_when_finished "git -C super reset --hard $ORIG" &&
        (cd super &&
                git config -f .gitmodules \
                        submodule.submodule.fetchrecursesubmodules blabla &&
@@ -126,8 +130,128 @@ test_expect_success 'error in history in fetchrecursesubmodule lets continue' '
                        HEAD b \
                        HEAD submodule \
                                >actual &&
-               test_cmp expect_error actual  &&
-               git reset --hard HEAD^
+               test_cmp expect_error actual
+       )
+'
+
+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 &&
+               test_cmp expect actual
+       )
+'
+
+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 &&
+               git submodule--helper config submodule.submodule.url "new_url" &&
+               git submodule--helper config submodule.submodule.url >actual &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success 'overwriting unstaged submodules config with "submodule--helper config"' '
+       test_when_finished "git -C super checkout .gitmodules" &&
+       (cd super &&
+               echo "newer_url" >expect &&
+               git submodule--helper config submodule.submodule.url "newer_url" &&
+               git submodule--helper config submodule.submodule.url >actual &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success 'writeable .gitmodules when it is in the working tree' '
+       git -C super submodule--helper config --check-writeable
+'
+
+test_expect_success 'writeable .gitmodules when it is nowhere in the repository' '
+       ORIG=$(git -C super rev-parse HEAD) &&
+       test_when_finished "git -C super reset --hard $ORIG" &&
+       (cd super &&
+               git rm .gitmodules &&
+               git commit -m "remove .gitmodules from the current branch" &&
+               git submodule--helper config --check-writeable
+       )
+'
+
+test_expect_success 'non-writeable .gitmodules when it is in the index but not in the working tree' '
+       test_when_finished "git -C super checkout .gitmodules" &&
+       (cd super &&
+               rm -f .gitmodules &&
+               test_must_fail git submodule--helper config --check-writeable
+       )
+'
+
+test_expect_success 'non-writeable .gitmodules when it is in the current branch but 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 &&
+               test_must_fail git submodule--helper config --check-writeable
+       )
+'
+
+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
        )
 '