
The submodule repo the test set up had the 'topic' branch checked out, meaning the repo's default branch (HEAD) is the 'topic' branch. The following tests then pretended to switch between the default branch and the 'topic' branch. This was papered over by continually adding commits to the 'topic' branch and checking if the submodule gets updated to this new commit. Return the submodule repo to the 'main' branch after setup so we can actually test the switching behavior. Signed-off-by: Jan Alexander Steffens (heftig) <heftig@archlinux.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
104 lines
2.1 KiB
Bash
Executable File
104 lines
2.1 KiB
Bash
Executable File
#!/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.
|
|
'
|
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
|
TEST_NO_CREATE_REPO=1
|
|
|
|
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
|
|
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
|
|
|
. ./test-lib.sh
|
|
|
|
test_expect_success 'setup' '
|
|
git config --global protocol.file.allow always
|
|
'
|
|
|
|
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 . &&
|
|
git commit -mb &&
|
|
git checkout main
|
|
) &&
|
|
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 &&
|
|
! grep branch .gitmodules
|
|
)
|
|
'
|
|
|
|
test_expect_success 'test submodule set-branch --branch' '
|
|
(cd super &&
|
|
git submodule set-branch --branch topic submodule &&
|
|
grep "branch = topic" .gitmodules &&
|
|
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 &&
|
|
! grep branch .gitmodules &&
|
|
git submodule update --remote &&
|
|
cat <<-\EOF >expect &&
|
|
a
|
|
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 &&
|
|
grep "branch = topic" .gitmodules &&
|
|
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 &&
|
|
! grep branch .gitmodules &&
|
|
git submodule update --remote &&
|
|
cat <<-\EOF >expect &&
|
|
a
|
|
EOF
|
|
git -C submodule show -s --pretty=%s >actual &&
|
|
test_cmp expect actual
|
|
)
|
|
'
|
|
|
|
test_done
|