2015-08-18 03:21:57 +03:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2014 Heiko Voigt
|
|
|
|
#
|
|
|
|
|
|
|
|
test_description='Test submodules config cache infrastructure
|
|
|
|
|
2015-08-18 03:21:59 +03:00
|
|
|
This test verifies that parsing .gitmodules configurations directly
|
|
|
|
from the database and from the worktree works.
|
2015-08-18 03:21:57 +03:00
|
|
|
'
|
|
|
|
|
|
|
|
TEST_NO_CREATE_REPO=1
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
2022-07-29 22:21:40 +03:00
|
|
|
test_expect_success 'setup' '
|
|
|
|
git config --global protocol.file.allow always
|
|
|
|
'
|
2015-08-18 03:21:57 +03:00
|
|
|
test_expect_success 'submodule config cache setup' '
|
|
|
|
mkdir submodule &&
|
|
|
|
(cd submodule &&
|
|
|
|
git init &&
|
|
|
|
echo a >a &&
|
|
|
|
git add . &&
|
|
|
|
git commit -ma
|
|
|
|
) &&
|
|
|
|
mkdir super &&
|
|
|
|
(cd super &&
|
|
|
|
git init &&
|
|
|
|
git submodule add ../submodule &&
|
|
|
|
git submodule add ../submodule a &&
|
|
|
|
git commit -m "add as submodule and as a" &&
|
|
|
|
git mv a b &&
|
|
|
|
git commit -m "move a to b"
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2017-07-26 00:39:14 +03:00
|
|
|
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 &&
|
2018-03-24 10:45:01 +03:00
|
|
|
test_must_fail test-tool submodule-config "" s 2>actual &&
|
2017-07-26 00:39:14 +03:00
|
|
|
test_i18ngrep "bad config" actual
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2015-08-18 03:21:57 +03:00
|
|
|
cat >super/expect <<EOF
|
|
|
|
Submodule name: 'a' for path 'a'
|
|
|
|
Submodule name: 'a' for path 'b'
|
|
|
|
Submodule name: 'submodule' for path 'submodule'
|
|
|
|
Submodule name: 'submodule' for path 'submodule'
|
|
|
|
EOF
|
|
|
|
|
|
|
|
test_expect_success 'test parsing and lookup of submodule config by path' '
|
|
|
|
(cd super &&
|
2018-03-24 10:45:01 +03:00
|
|
|
test-tool submodule-config \
|
2015-08-18 03:21:57 +03:00
|
|
|
HEAD^ a \
|
|
|
|
HEAD b \
|
|
|
|
HEAD^ submodule \
|
|
|
|
HEAD submodule \
|
|
|
|
>actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'test parsing and lookup of submodule config by name' '
|
|
|
|
(cd super &&
|
2018-03-24 10:45:01 +03:00
|
|
|
test-tool submodule-config --name \
|
2015-08-18 03:21:57 +03:00
|
|
|
HEAD^ a \
|
|
|
|
HEAD a \
|
|
|
|
HEAD^ submodule \
|
|
|
|
HEAD submodule \
|
|
|
|
>actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
cat >super/expect_error <<EOF
|
|
|
|
Submodule name: 'a' for path 'b'
|
|
|
|
Submodule name: 'submodule' for path 'submodule'
|
|
|
|
EOF
|
|
|
|
|
2018-10-05 16:05:54 +03:00
|
|
|
test_expect_success 'error in history of one submodule config lets continue, stderr message contains blob ref' '
|
2018-10-05 16:05:55 +03:00
|
|
|
ORIG=$(git -C super rev-parse HEAD) &&
|
|
|
|
test_when_finished "git -C super reset --hard $ORIG" &&
|
2015-08-18 03:21:57 +03:00
|
|
|
(cd super &&
|
|
|
|
cp .gitmodules .gitmodules.bak &&
|
|
|
|
echo " value = \"" >>.gitmodules &&
|
|
|
|
git add .gitmodules &&
|
|
|
|
mv .gitmodules.bak .gitmodules &&
|
|
|
|
git commit -m "add error" &&
|
2016-07-28 15:49:11 +03:00
|
|
|
sha1=$(git rev-parse HEAD) &&
|
2018-03-24 10:45:01 +03:00
|
|
|
test-tool submodule-config \
|
2016-07-28 15:49:11 +03:00
|
|
|
HEAD b \
|
|
|
|
HEAD submodule \
|
2018-10-05 16:05:54 +03:00
|
|
|
>actual \
|
|
|
|
2>actual_stderr &&
|
|
|
|
test_cmp expect_error actual &&
|
|
|
|
test_i18ngrep "submodule-blob $sha1:.gitmodules" actual_stderr >/dev/null
|
2016-07-28 15:49:11 +03:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2016-11-22 23:14:37 +03:00
|
|
|
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}) &&
|
2018-03-24 10:45:01 +03:00
|
|
|
test-tool submodule-config $commit b >expect &&
|
|
|
|
test-tool submodule-config $tree b >actual.1 &&
|
|
|
|
test-tool submodule-config new_tag b >actual.2 &&
|
2016-11-22 23:14:37 +03:00
|
|
|
test_cmp expect actual.1 &&
|
|
|
|
test_cmp expect actual.2
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2015-08-18 03:22:00 +03:00
|
|
|
test_expect_success 'error in history in fetchrecursesubmodule lets continue' '
|
2018-10-05 16:05:55 +03:00
|
|
|
ORIG=$(git -C super rev-parse HEAD) &&
|
|
|
|
test_when_finished "git -C super reset --hard $ORIG" &&
|
2015-08-18 03:22:00 +03:00
|
|
|
(cd super &&
|
|
|
|
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" &&
|
2018-03-24 10:45:01 +03:00
|
|
|
test-tool submodule-config \
|
2015-08-18 03:22:00 +03:00
|
|
|
HEAD b \
|
|
|
|
HEAD submodule \
|
|
|
|
>actual &&
|
2018-10-05 16:05:55 +03:00
|
|
|
test_cmp expect_error actual
|
2015-08-18 03:22:00 +03:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2022-11-08 17:10:32 +03:00
|
|
|
test_expect_success 'reading submodules config from the working tree' '
|
2018-10-05 16:05:56 +03:00
|
|
|
(cd super &&
|
|
|
|
echo "../submodule" >expect &&
|
2022-11-08 17:10:32 +03:00
|
|
|
test-tool submodule config-list submodule.submodule.url >actual &&
|
2018-10-05 16:05:56 +03:00
|
|
|
test_cmp expect actual
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2022-11-08 17:10:32 +03:00
|
|
|
test_expect_success 'unsetting submodules config from the working tree' '
|
2019-02-08 14:21:31 +03:00
|
|
|
(cd super &&
|
2022-11-08 17:10:32 +03:00
|
|
|
test-tool submodule config-unset submodule.submodule.url &&
|
|
|
|
test-tool submodule config-list submodule.submodule.url >actual &&
|
2019-02-08 14:21:31 +03:00
|
|
|
test_must_be_empty actual
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
|
2022-11-08 17:10:32 +03:00
|
|
|
test_expect_success 'writing submodules config' '
|
2018-10-05 16:05:56 +03:00
|
|
|
(cd super &&
|
|
|
|
echo "new_url" >expect &&
|
2022-11-08 17:10:32 +03:00
|
|
|
test-tool submodule config-set submodule.submodule.url "new_url" &&
|
|
|
|
test-tool submodule config-list submodule.submodule.url >actual &&
|
2018-10-05 16:05:56 +03:00
|
|
|
test_cmp expect actual
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2022-11-08 17:10:32 +03:00
|
|
|
test_expect_success 'overwriting unstaged submodules config' '
|
2018-10-05 16:05:56 +03:00
|
|
|
test_when_finished "git -C super checkout .gitmodules" &&
|
|
|
|
(cd super &&
|
|
|
|
echo "newer_url" >expect &&
|
2022-11-08 17:10:32 +03:00
|
|
|
test-tool submodule config-set submodule.submodule.url "newer_url" &&
|
|
|
|
test-tool submodule config-list submodule.submodule.url >actual &&
|
2018-10-05 16:05:56 +03:00
|
|
|
test_cmp expect actual
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2018-10-05 16:05:59 +03:00
|
|
|
test_expect_success 'writeable .gitmodules when it is in the working tree' '
|
2022-11-08 17:10:32 +03:00
|
|
|
test-tool -C super submodule config-writeable
|
2018-10-05 16:05:59 +03:00
|
|
|
'
|
|
|
|
|
|
|
|
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" &&
|
2022-11-08 17:10:32 +03:00
|
|
|
test-tool submodule config-writeable
|
2018-10-05 16:05:59 +03:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
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 &&
|
2022-11-08 17:10:32 +03:00
|
|
|
test_must_fail test-tool submodule config-writeable
|
2018-10-05 16:05:59 +03:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
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 &&
|
2022-11-08 17:10:32 +03:00
|
|
|
test_must_fail test-tool submodule config-writeable
|
2018-10-05 16:05:59 +03:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2018-10-25 19:18:12 +03:00
|
|
|
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 &&
|
2022-11-08 17:10:32 +03:00
|
|
|
test-tool submodule config-set submodule.submodule.url "staged_url" &&
|
2018-10-25 19:18:12 +03:00
|
|
|
git add .gitmodules &&
|
|
|
|
rm -f .gitmodules &&
|
|
|
|
echo "staged_url" >expect &&
|
2022-11-08 17:10:32 +03:00
|
|
|
test-tool submodule config-list submodule.submodule.url >actual &&
|
2018-10-25 19:18:12 +03:00
|
|
|
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 &&
|
2022-11-08 17:10:32 +03:00
|
|
|
test-tool submodule config-list submodule.submodule.url >actual &&
|
2018-10-25 19:18:12 +03:00
|
|
|
test_cmp expect actual
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2018-10-25 19:18:13 +03:00
|
|
|
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
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
get_oid: handle NULL repo->index
When get_oid() and its helpers see an index name like ":.gitmodules",
they try to load the index on demand, like:
if (repo->index->cache)
repo_read_index(repo);
However, that misses the case when "repo->index" itself is NULL; we'll
segfault in the conditional.
This never happens with the_repository; there we always point its index
field to &the_index. But a submodule repository may have a NULL index
field until somebody calls repo_read_index().
This bug is triggered by t7411, but it was hard to notice because it's
in an expect_failure block. That test was added by 2b1257e463 (t/helper:
add test-submodule-nested-repo-config, 2018-10-25). Back then we had no
easy way to access the .gitmodules blob of a submodule repo, so we
expected (and got) an error message to that effect. Later, d9b8b8f896
(submodule-config.c: use repo_get_oid for reading .gitmodules,
2019-04-16) started looking in the correct repo, which is when we
started triggering the segfault.
With this fix, the test starts passing (once we clean it up as its
comment instructs).
Note that as far as I know, this bug could not be triggered outside of
the test suite. It requires resolving an index name in a submodule, and
all of the code paths (aside from test-tool) which do that either load
the index themselves, or always pass the_repository.
Ultimately it comes from 3a7a698e93 (sha1-name.c: remove implicit
dependency on the_index, 2019-01-12), which replaced a check of
"the_index.cache" with "repo->index->cache". So even if there is another
way to trigger it, it wouldn't affect any versions before then.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-05-14 16:54:55 +03:00
|
|
|
test_expect_success 'reading nested submodules config when .gitmodules is not in the working tree' '
|
2018-10-25 19:18:13 +03:00
|
|
|
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 &&
|
get_oid: handle NULL repo->index
When get_oid() and its helpers see an index name like ":.gitmodules",
they try to load the index on demand, like:
if (repo->index->cache)
repo_read_index(repo);
However, that misses the case when "repo->index" itself is NULL; we'll
segfault in the conditional.
This never happens with the_repository; there we always point its index
field to &the_index. But a submodule repository may have a NULL index
field until somebody calls repo_read_index().
This bug is triggered by t7411, but it was hard to notice because it's
in an expect_failure block. That test was added by 2b1257e463 (t/helper:
add test-submodule-nested-repo-config, 2018-10-25). Back then we had no
easy way to access the .gitmodules blob of a submodule repo, so we
expected (and got) an error message to that effect. Later, d9b8b8f896
(submodule-config.c: use repo_get_oid for reading .gitmodules,
2019-04-16) started looking in the correct repo, which is when we
started triggering the segfault.
With this fix, the test starts passing (once we clean it up as its
comment instructs).
Note that as far as I know, this bug could not be triggered outside of
the test suite. It requires resolving an index name in a submodule, and
all of the code paths (aside from test-tool) which do that either load
the index themselves, or always pass the_repository.
Ultimately it comes from 3a7a698e93 (sha1-name.c: remove implicit
dependency on the_index, 2019-01-12), which replaced a check of
"the_index.cache" with "repo->index->cache". So even if there is another
way to trigger it, it wouldn't affect any versions before then.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-05-14 16:54:55 +03:00
|
|
|
test_must_be_empty warning &&
|
2018-10-25 19:18:13 +03:00
|
|
|
test_cmp expect actual
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2015-08-18 03:21:57 +03:00
|
|
|
test_done
|