gc: handle & check gc.reflogExpire config
[gitweb.git] / t / t7411-submodule-config.sh
index 47562ce4654db9d763cdf0c6d6b91724489110ff..89690b7adb85a9dbcda4fe85c5ab672716f41de8 100755 (executable)
@@ -31,6 +31,21 @@ test_expect_success 'submodule config cache setup' '
        )
 '
 
+test_expect_success 'configuration parsing with error' '
+       test_when_finished "rm -rf repo" &&
+       test_create_repo repo &&
+       cat >repo/.gitmodules <<-\EOF &&
+       [submodule "s"]
+               path
+               ignore
+       EOF
+       (
+               cd repo &&
+               test_must_fail test-tool submodule-config "" s 2>actual &&
+               test_i18ngrep "bad config" actual
+       )
+'
+
 cat >super/expect <<EOF
 Submodule name: 'a' for path 'a'
 Submodule name: 'a' for path 'b'
@@ -40,7 +55,7 @@ EOF
 
 test_expect_success 'test parsing and lookup of submodule config by path' '
        (cd super &&
-               test-submodule-config \
+               test-tool submodule-config \
                        HEAD^ a \
                        HEAD b \
                        HEAD^ submodule \
@@ -52,7 +67,7 @@ test_expect_success 'test parsing and lookup of submodule config by path' '
 
 test_expect_success 'test parsing and lookup of submodule config by name' '
        (cd super &&
-               test-submodule-config --name \
+               test-tool submodule-config --name \
                        HEAD^ a \
                        HEAD a \
                        HEAD^ submodule \
@@ -67,97 +82,171 @@ Submodule name: 'a' for path 'b'
 Submodule name: 'submodule' for path 'submodule'
 EOF
 
-test_expect_success 'error in one submodule config lets continue' '
+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 &&
                git add .gitmodules &&
                mv .gitmodules.bak .gitmodules &&
                git commit -m "add error" &&
-               test-submodule-config \
+               sha1=$(git rev-parse HEAD) &&
+               test-tool submodule-config \
                        HEAD b \
                        HEAD submodule \
-                               >actual &&
-               test_cmp expect_error actual
+                               >actual \
+                               2>actual_stderr &&
+               test_cmp expect_error actual &&
+               test_i18ngrep "submodule-blob $sha1:.gitmodules" actual_stderr >/dev/null
+       )
+'
+
+test_expect_success 'using different treeishs works' '
+       (
+               cd super &&
+               git tag new_tag &&
+               tree=$(git rev-parse HEAD^{tree}) &&
+               commit=$(git rev-parse HEAD^{commit}) &&
+               test-tool submodule-config $commit b >expect &&
+               test-tool submodule-config $tree b >actual.1 &&
+               test-tool submodule-config new_tag b >actual.2 &&
+               test_cmp expect actual.1 &&
+               test_cmp expect actual.2
        )
 '
 
-test_expect_success 'error message contains blob reference' '
+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 &&
-               sha1=$(git rev-parse HEAD) &&
-               test-submodule-config \
+               git config -f .gitmodules \
+                       submodule.submodule.fetchrecursesubmodules blabla &&
+               git add .gitmodules &&
+               git config --unset -f .gitmodules \
+                       submodule.submodule.fetchrecursesubmodules &&
+               git commit -m "add error in fetchrecursesubmodules" &&
+               test-tool submodule-config \
                        HEAD b \
                        HEAD submodule \
-                               2>actual_err &&
-               test_i18ngrep "submodule-blob $sha1:.gitmodules" actual_err >/dev/null
+                               >actual &&
+               test_cmp expect_error actual
        )
 '
 
-cat >super/expect_url <<EOF
-Submodule url: 'git@somewhere.else.net:a.git' for path 'b'
-Submodule url: 'git@somewhere.else.net:submodule.git' for path 'submodule'
-EOF
+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
+       )
+'
 
-cat >super/expect_local_path <<EOF
-Submodule name: 'a' for path 'c'
-Submodule name: 'submodule' for path 'submodule'
-EOF
+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 'reading of local configuration' '
+test_expect_success 'overwriting unstaged submodules config with "submodule--helper config"' '
+       test_when_finished "git -C super checkout .gitmodules" &&
        (cd super &&
-               old_a=$(git config submodule.a.url) &&
-               old_submodule=$(git config submodule.submodule.url) &&
-               git config submodule.a.url git@somewhere.else.net:a.git &&
-               git config submodule.submodule.url git@somewhere.else.net:submodule.git &&
-               test-submodule-config --url \
-                       "" b \
-                       "" submodule \
-                               >actual &&
-               test_cmp expect_url actual &&
-               git config submodule.a.path c &&
-               test-submodule-config \
-                       "" c \
-                       "" submodule \
-                               >actual &&
-               test_cmp expect_local_path actual &&
-               git config submodule.a.url $old_a &&
-               git config submodule.submodule.url $old_submodule &&
-               git config --unset submodule.a.path c
+               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
        )
 '
 
-cat >super/expect_fetchrecurse_die.err <<EOF
-fatal: bad submodule.submodule.fetchrecursesubmodules argument: blabla
-EOF
+test_expect_success 'writeable .gitmodules when it is in the working tree' '
+       git -C super submodule--helper config --check-writeable
+'
 
-test_expect_success 'local error in fetchrecursesubmodule dies early' '
+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 config submodule.submodule.fetchrecursesubmodules blabla &&
-               test_must_fail test-submodule-config \
-                       "" b \
-                       "" submodule \
-                               >actual.out 2>actual.err &&
-               touch expect_fetchrecurse_die.out &&
-               test_cmp expect_fetchrecurse_die.out actual.out  &&
-               test_cmp expect_fetchrecurse_die.err actual.err  &&
-               git config --unset submodule.submodule.fetchrecursesubmodules
+               git rm .gitmodules &&
+               git commit -m "remove .gitmodules from the current branch" &&
+               git submodule--helper config --check-writeable
        )
 '
 
-test_expect_success 'error in history in fetchrecursesubmodule lets continue' '
+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 &&
-               git config -f .gitmodules \
-                       submodule.submodule.fetchrecursesubmodules blabla &&
+               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 &&
-               git config --unset -f .gitmodules \
-                       submodule.submodule.fetchrecursesubmodules &&
-               git commit -m "add error in fetchrecursesubmodules" &&
-               test-submodule-config \
-                       HEAD b \
-                       HEAD submodule \
-                               >actual &&
-               test_cmp expect_error actual  &&
-               git reset --hard HEAD^
+               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
+       )
+'
+
+# When this test eventually passes, before turning it into
+# test_expect_success, remember to replace the test_i18ngrep below with
+# a "test_must_be_empty warning" to be sure that the warning is actually
+# removed from the code.
+test_expect_failure '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_i18ngrep "nested submodules without %s in the working tree are not supported yet" warning &&
+               test_cmp expect actual
        )
 '