1
+#!/bin/sh
2
+
3
+test_description='submodulePathConfig extension works as expected'
4
+
5
+. ./test-lib.sh
6
+. "$TEST_DIRECTORY"/lib-verify-submodule-gitdir-path.sh
7
+
8
+test_expect_success 'setup: allow file protocol' '
9
+ git config --global protocol.file.allow always
10
+'
11
+
12
+test_expect_success 'create repo with mixed extension submodules' '
13
+ git init -b main legacy-sub &&
14
+ test_commit -C legacy-sub legacy-initial &&
15
+ legacy_rev=$(git -C legacy-sub rev-parse HEAD) &&
16
+
17
+ git init -b main new-sub &&
18
+ test_commit -C new-sub new-initial &&
19
+ new_rev=$(git -C new-sub rev-parse HEAD) &&
20
+
21
+ git init -b main main &&
22
+ (
23
+ cd main &&
24
+ git submodule add ../legacy-sub legacy &&
25
+ test_commit legacy-sub &&
26
+
27
+ # trigger the "die_path_inside_submodule" check
28
+ test_must_fail git submodule add ../new-sub "legacy/nested" &&
29
+
30
+ git config core.repositoryformatversion 1 &&
31
+ git config extensions.submodulePathConfig true &&
32
+
33
+ git submodule add ../new-sub "New Sub" &&
34
+ test_commit new &&
35
+
36
+ # retrigger the "die_path_inside_submodule" check with encoding
37
+ test_must_fail git submodule add ../new-sub "New Sub/nested2"
38
+ )
39
+'
40
+
41
+test_expect_success 'verify new submodule gitdir config' '
42
+ git -C main config submodule."New Sub".gitdir >actual &&
43
+ echo ".git/modules/New Sub" >expect &&
44
+ test_cmp expect actual &&
45
+ verify_submodule_gitdir_path main "New Sub" "modules/New Sub"
46
+'
47
+
48
+test_expect_success 'manual add and verify legacy submodule gitdir config' '
49
+ # the legacy module should not contain a gitdir config, because it
50
+ # was added before the extension was enabled. Add and test it.
51
+ test_must_fail git -C main config submodule.legacy.gitdir &&
52
+ git -C main config submodule.legacy.gitdir .git/modules/legacy &&
53
+ git -C main config submodule.legacy.gitdir >actual &&
54
+ echo ".git/modules/legacy" >expect &&
55
+ test_cmp expect actual &&
56
+ verify_submodule_gitdir_path main "legacy" "modules/legacy"
57
+'
58
+
59
+test_expect_success 'gitdir config path is relative for both absolute and relative urls' '
60
+ test_when_finished "rm -rf relative-cfg-path-test" &&
61
+ git init -b main relative-cfg-path-test &&
62
+ (
63
+ cd relative-cfg-path-test &&
64
+ git config core.repositoryformatversion 1 &&
65
+ git config extensions.submodulePathConfig true &&
66
+
67
+ # Test with absolute URL
68
+ git submodule add "$TRASH_DIRECTORY/new-sub" sub-abs &&
69
+ git config submodule.sub-abs.gitdir >actual &&
70
+ echo ".git/modules/sub-abs" >expect &&
71
+ test_cmp expect actual &&
72
+
73
+ # Test with relative URL
74
+ git submodule add ../new-sub sub-rel &&
75
+ git config submodule.sub-rel.gitdir >actual &&
76
+ echo ".git/modules/sub-rel" >expect &&
77
+ test_cmp expect actual
78
+ )
79
+'
80
+
81
+test_expect_success 'clone from repo with both legacy and new-style submodules' '
82
+ git clone --recurse-submodules main cloned-non-extension &&
83
+ (
84
+ cd cloned-non-extension &&
85
+
86
+ test_path_is_dir .git/modules/legacy &&
87
+ test_path_is_dir .git/modules/"New Sub" &&
88
+
89
+ test_must_fail git config submodule.legacy.gitdir &&
90
+ test_must_fail git config submodule."New Sub".gitdir &&
91
+
92
+ git submodule status >list &&
93
+ test_grep "$legacy_rev legacy" list &&
94
+ test_grep "$new_rev New Sub" list
95
+ ) &&
96
+
97
+ git clone -c extensions.submodulePathConfig=true --recurse-submodules main cloned-extension &&
98
+ (
99
+ cd cloned-extension &&
100
+
101
+ test_path_is_dir .git/modules/legacy &&
102
+ test_path_is_dir ".git/modules/New Sub" &&
103
+
104
+ git config submodule.legacy.gitdir &&
105
+ git config submodule."New Sub".gitdir &&
106
+
107
+ git submodule status >list &&
108
+ test_grep "$legacy_rev legacy" list &&
109
+ test_grep "$new_rev New Sub" list
110
+ )
111
+'
112
+
113
+test_expect_success 'commit and push changes to encoded submodules' '
114
+ git -C legacy-sub config receive.denyCurrentBranch updateInstead &&
115
+ git -C new-sub config receive.denyCurrentBranch updateInstead &&
116
+ git -C main config receive.denyCurrentBranch updateInstead &&
117
+ (
118
+ cd cloned-extension &&
119
+
120
+ git -C legacy switch --track -C main origin/main &&
121
+ test_commit -C legacy second-commit &&
122
+ git -C legacy push &&
123
+
124
+ git -C "New Sub" switch --track -C main origin/main &&
125
+ test_commit -C "New Sub" second-commit &&
126
+ git -C "New Sub" push &&
127
+
128
+ # Stage and commit submodule changes in superproject
129
+ git switch --track -C main origin/main &&
130
+ git add legacy "New Sub" &&
131
+ git commit -m "update submodules" &&
132
+
133
+ # push superproject commit to main repo
134
+ git push
135
+ ) &&
136
+
137
+ # update expected legacy & new submodule checksums
138
+ legacy_rev=$(git -C legacy-sub rev-parse HEAD) &&
139
+ new_rev=$(git -C new-sub rev-parse HEAD)
140
+'
141
+
142
+test_expect_success 'fetch mixed submodule changes and verify updates' '
143
+ (
144
+ cd main &&
145
+
146
+ # only update submodules because superproject was
147
+ # pushed into at the end of last test
148
+ git submodule update --init --recursive &&
149
+
150
+ test_path_is_dir .git/modules/legacy &&
151
+ test_path_is_dir ".git/modules/New Sub" &&
152
+
153
+ # Verify both submodules are at the expected commits
154
+ git submodule status >list &&
155
+ test_grep "$legacy_rev legacy" list &&
156
+ test_grep "$new_rev New Sub" list
157
+ )
158
+'
159
+
160
+test_done