t7420: test that we correctly handle renamed submodules

Create a second submodule with a name that differs from its path. Test that calling set-url 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 bd1c20ccd70d7452566bbc56ca2cf1fbb73d747c
1 file changed +24 -2
t/t7420-submodule-set-url.sh
+24 -2
@@ -25,17 +25,26 @@ test_expect_success 'submodule config cache setup' '
25 git add file &&
26 git commit -ma
27 ) &&
28 + mkdir namedsubmodule &&
29 + (
30 + cd namedsubmodule &&
31 + git init &&
32 + echo 1 >file &&
33 + git add file &&
34 + git commit -m1
35 + ) &&
36 mkdir super &&
37 (
38 cd super &&
39 git init &&
40 git submodule add ../submodule &&
33 - git commit -m "add submodule"
41 + git submodule add --name thename ../namedsubmodule thepath &&
42 + git commit -m "add submodules"
43 )
44 '
45
46 test_expect_success 'test submodule set-url' '
38 - # add a commit and move the submodule (change the url)
47 + # add commits and move the submodules (change the urls)
48 (
49 cd submodule &&
50 echo b >>file &&
@@ -44,15 +53,28 @@ test_expect_success 'test submodule set-url' '
53 ) &&
54 mv submodule newsubmodule &&
55
56 + (
57 + cd namedsubmodule &&
58 + echo 2 >>file &&
59 + git add file &&
60 + git commit -m2
61 + ) &&
62 + mv namedsubmodule newnamedsubmodule &&
63 +
64 git -C newsubmodule show >expect &&
65 + git -C newnamedsubmodule show >>expect &&
66 (
67 cd super &&
68 test_must_fail git submodule update --remote &&
69 git submodule set-url submodule ../newsubmodule &&
70 test_cmp_config ../newsubmodule -f .gitmodules submodule.submodule.url &&
71 + git submodule set-url thepath ../newnamedsubmodule &&
72 + test_cmp_config ../newnamedsubmodule -f .gitmodules submodule.thename.url &&
73 + test_cmp_config "" -f .gitmodules --default "" submodule.thepath.url &&
74 git submodule update --remote
75 ) &&
76 git -C super/submodule show >actual &&
77 + git -C super/thepath show >>actual &&
78 test_cmp expect actual
79 '
80