2019-02-08 11:21:34 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2019 Denton Liu
|
|
|
|
#
|
|
|
|
|
|
|
|
test_description='Test submodules set-branch subcommand
|
|
|
|
|
|
|
|
This test verifies that the set-branch subcommand of git-submodule is working
|
|
|
|
as expected.
|
|
|
|
'
|
|
|
|
|
2022-08-31 23:14:22 +00:00
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
2019-02-08 11:21:34 +00:00
|
|
|
TEST_NO_CREATE_REPO=1
|
2023-10-03 18:50:44 +00:00
|
|
|
|
|
|
|
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
|
|
|
|
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
|
|
|
|
2019-02-08 11:21:34 +00:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
2022-07-29 19:21:40 +00:00
|
|
|
test_expect_success 'setup' '
|
|
|
|
git config --global protocol.file.allow always
|
|
|
|
'
|
|
|
|
|
2019-02-08 11:21:34 +00:00
|
|
|
test_expect_success 'submodule config cache setup' '
|
|
|
|
mkdir submodule &&
|
|
|
|
(cd submodule &&
|
|
|
|
git init &&
|
|
|
|
echo a >a &&
|
|
|
|
git add . &&
|
|
|
|
git commit -ma &&
|
|
|
|
git checkout -b topic &&
|
|
|
|
echo b >a &&
|
|
|
|
git add . &&
|
2023-10-03 18:50:44 +00:00
|
|
|
git commit -mb &&
|
|
|
|
git checkout main
|
2019-02-08 11:21:34 +00:00
|
|
|
) &&
|
|
|
|
mkdir super &&
|
|
|
|
(cd super &&
|
|
|
|
git init &&
|
|
|
|
git submodule add ../submodule &&
|
|
|
|
git commit -m "add submodule"
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'ensure submodule branch is unset' '
|
|
|
|
(cd super &&
|
2023-10-03 18:50:45 +00:00
|
|
|
test_cmp_config "" -f .gitmodules --default "" submodule.submodule.branch
|
2019-02-08 11:21:34 +00:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'test submodule set-branch --branch' '
|
|
|
|
(cd super &&
|
|
|
|
git submodule set-branch --branch topic submodule &&
|
2023-10-03 18:50:45 +00:00
|
|
|
test_cmp_config topic -f .gitmodules submodule.submodule.branch &&
|
2019-02-08 11:21:34 +00:00
|
|
|
git submodule update --remote &&
|
|
|
|
cat <<-\EOF >expect &&
|
|
|
|
b
|
|
|
|
EOF
|
|
|
|
git -C submodule show -s --pretty=%s >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'test submodule set-branch --default' '
|
|
|
|
(cd super &&
|
|
|
|
git submodule set-branch --default submodule &&
|
2023-10-03 18:50:45 +00:00
|
|
|
test_cmp_config "" -f .gitmodules --default "" submodule.submodule.branch &&
|
2019-02-08 11:21:34 +00:00
|
|
|
git submodule update --remote &&
|
|
|
|
cat <<-\EOF >expect &&
|
2023-10-03 18:50:44 +00:00
|
|
|
a
|
2019-02-08 11:21:34 +00:00
|
|
|
EOF
|
|
|
|
git -C submodule show -s --pretty=%s >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'test submodule set-branch -b' '
|
|
|
|
(cd super &&
|
|
|
|
git submodule set-branch -b topic submodule &&
|
2023-10-03 18:50:45 +00:00
|
|
|
test_cmp_config topic -f .gitmodules submodule.submodule.branch &&
|
2019-02-08 11:21:34 +00:00
|
|
|
git submodule update --remote &&
|
|
|
|
cat <<-\EOF >expect &&
|
|
|
|
b
|
|
|
|
EOF
|
|
|
|
git -C submodule show -s --pretty=%s >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'test submodule set-branch -d' '
|
|
|
|
(cd super &&
|
|
|
|
git submodule set-branch -d submodule &&
|
2023-10-03 18:50:45 +00:00
|
|
|
test_cmp_config "" -f .gitmodules --default "" submodule.submodule.branch &&
|
2019-02-08 11:21:34 +00:00
|
|
|
git submodule update --remote &&
|
|
|
|
cat <<-\EOF >expect &&
|
2023-10-03 18:50:44 +00:00
|
|
|
a
|
2019-02-08 11:21:34 +00:00
|
|
|
EOF
|
|
|
|
git -C submodule show -s --pretty=%s >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_done
|