t7419: test that we correctly handle renamed submodules

Add the submodule again with an explicitly different name and path. Test that calling set-branch modifies the correct .gitmodules entries. Make sure we don't create a section named after the path instead of the name. Signed-off-by: Jan Alexander Steffens (heftig) <heftig@archlinux.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jan Alexander Steffens (heftig) committed Oct 3, 2023 at 20:50 UTC 32bff3675e6b4dc5ae93f0777e5da709f6576275
1 file changed +29 -1
t/t7419-submodule-set-branch.sh
+29 -1
@@ -38,7 +38,8 @@ test_expect_success 'submodule config cache setup' '
38 (cd super &&
39 git init &&
40 git submodule add ../submodule &&
41 - git commit -m "add submodule"
41 + git submodule add --name thename ../submodule thepath &&
42 + git commit -m "add submodules"
43 )
44 '
45
@@ -100,4 +101,31 @@ test_expect_success 'test submodule set-branch -d' '
101 )
102 '
103
104 +test_expect_success 'test submodule set-branch --branch with named submodule' '
105 + (cd super &&
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 &&
111 + b
112 + EOF
113 + git -C thepath show -s --pretty=%s >actual &&
114 + test_cmp expect actual
115 + )
116 +'
117 +
118 +test_expect_success 'test submodule set-branch --default with named submodule' '
119 + (cd super &&
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 &&
124 + a
125 + EOF
126 + git -C thepath show -s --pretty=%s >actual &&
127 + test_cmp expect actual
128 + )
129 +'
130 +
131 test_done