2019-02-08 12:21:34 +01: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.
|
|
|
|
'
|
|
|
|
|
|
|
|
TEST_NO_CREATE_REPO=1
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
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
|
|
|
|
) &&
|
|
|
|
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 &&
|
2019-10-22 11:57:01 +02:00
|
|
|
! grep branch .gitmodules
|
2019-02-08 12:21:34 +01:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
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' '
|
2020-06-24 16:46:30 +02:00
|
|
|
test_commit -C submodule c &&
|
2019-02-08 12:21:34 +01:00
|
|
|
(cd super &&
|
|
|
|
git submodule set-branch --default submodule &&
|
2019-10-22 11:57:01 +02:00
|
|
|
! grep branch .gitmodules &&
|
2019-02-08 12:21:34 +01:00
|
|
|
git submodule update --remote &&
|
|
|
|
cat <<-\EOF >expect &&
|
2020-06-24 16:46:30 +02:00
|
|
|
c
|
2019-02-08 12:21:34 +01:00
|
|
|
EOF
|
|
|
|
git -C submodule show -s --pretty=%s >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'test submodule set-branch -b' '
|
2020-06-24 16:46:30 +02:00
|
|
|
test_commit -C submodule b &&
|
2019-02-08 12:21:34 +01:00
|
|
|
(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' '
|
2020-06-24 16:46:30 +02:00
|
|
|
test_commit -C submodule d &&
|
2019-02-08 12:21:34 +01:00
|
|
|
(cd super &&
|
|
|
|
git submodule set-branch -d submodule &&
|
2019-10-22 11:57:01 +02:00
|
|
|
! grep branch .gitmodules &&
|
2019-02-08 12:21:34 +01:00
|
|
|
git submodule update --remote &&
|
|
|
|
cat <<-\EOF >expect &&
|
2020-06-24 16:46:30 +02:00
|
|
|
d
|
2019-02-08 12:21:34 +01:00
|
|
|
EOF
|
|
|
|
git -C submodule show -s --pretty=%s >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_done
|