3 # Copyright (c) 2019 Denton Liu
6 test_description
='Test submodules set-branch subcommand
8 This test verifies that the set-branch subcommand of git-submodule is working
12 TEST_PASSES_SANITIZE_LEAK
=true
15 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
16 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
20 test_expect_success
'setup' '
21 git config --global protocol.file.allow always
24 test_expect_success
'submodule config cache setup' '
31 git checkout -b topic &&
40 git submodule add ../submodule &&
41 git submodule add --name thename ../submodule thepath &&
42 git commit -m "add submodules"
46 test_expect_success
'ensure submodule branch is unset' '
48 test_cmp_config "" -f .gitmodules --default "" submodule.submodule.branch
52 test_expect_success
'test submodule set-branch --branch' '
54 git submodule set-branch --branch topic submodule &&
55 test_cmp_config topic -f .gitmodules submodule.submodule.branch &&
56 git submodule update --remote &&
57 cat <<-\EOF >expect &&
60 git -C submodule show -s --pretty=%s >actual &&
61 test_cmp expect actual
65 test_expect_success
'test submodule set-branch --default' '
67 git submodule set-branch --default submodule &&
68 test_cmp_config "" -f .gitmodules --default "" submodule.submodule.branch &&
69 git submodule update --remote &&
70 cat <<-\EOF >expect &&
73 git -C submodule show -s --pretty=%s >actual &&
74 test_cmp expect actual
78 test_expect_success
'test submodule set-branch -b' '
80 git submodule set-branch -b topic submodule &&
81 test_cmp_config topic -f .gitmodules submodule.submodule.branch &&
82 git submodule update --remote &&
83 cat <<-\EOF >expect &&
86 git -C submodule show -s --pretty=%s >actual &&
87 test_cmp expect actual
91 test_expect_success
'test submodule set-branch -d' '
93 git submodule set-branch -d submodule &&
94 test_cmp_config "" -f .gitmodules --default "" submodule.submodule.branch &&
95 git submodule update --remote &&
96 cat <<-\EOF >expect &&
99 git -C submodule show -s --pretty=%s >actual &&
100 test_cmp expect actual
104 test_expect_success
'test submodule set-branch --branch with named submodule' '
106 git submodule set-branch --branch topic thepath &&
107 test_cmp_config topic -f .gitmodules submodule.thename.branch &&
108 test_cmp_config "" -f .gitmodules --default "" submodule.thepath.branch &&
109 git submodule update --remote &&
110 cat <<-\EOF >expect &&
113 git -C thepath show -s --pretty=%s >actual &&
114 test_cmp expect actual
118 test_expect_success
'test submodule set-branch --default with named submodule' '
120 git submodule set-branch --default thepath &&
121 test_cmp_config "" -f .gitmodules --default "" submodule.thename.branch &&
122 git submodule update --remote &&
123 cat <<-\EOF >expect &&
126 git -C thepath show -s --pretty=%s >actual &&
127 test_cmp expect actual