125
)
126
'
127
128
+test_expect_success 'preparing second superproject with a nested submodule plus partial clone' '
129
+ test_create_repo supersuper &&
130
+ (
131
+ cd supersuper &&
132
+ echo "I am super super." >file &&
133
+ git add file &&
134
+ git commit -m B-super-super-initial
135
+ git submodule add "file://$base_dir/super" subwithsub &&
136
+ git commit -m B-super-super-added &&
137
+ git submodule update --init --recursive &&
138
+ git repack -ad
139
+ ) &&
140
+ git clone supersuper supersuper2 &&
141
+ (
142
+ cd supersuper2 &&
143
+ git submodule update --init
144
+ )
145
+'
146
+
147
+# At this point there are three root-level positories: A, B, super and super2
148
+
149
+test_expect_success 'nested submodule alternate in works and is actually used' '
150
+ test_when_finished "rm -rf supersuper-clone" &&
151
+ git clone --recursive --reference supersuper supersuper supersuper-clone &&
152
+ (
153
+ cd supersuper-clone &&
154
+ # test superproject has alternates setup correctly
155
+ test_alternate_is_used .git/objects/info/alternates . &&
156
+ # immediate submodule has alternate:
157
+ test_alternate_is_used .git/modules/subwithsub/objects/info/alternates subwithsub &&
158
+ # nested submodule also has alternate:
159
+ test_alternate_is_used .git/modules/subwithsub/modules/sub/objects/info/alternates subwithsub/sub
160
+ )
161
+'
162
+
163
+check_that_two_of_three_alternates_are_used() {
164
+ test_alternate_is_used .git/objects/info/alternates . &&
165
+ # immediate submodule has alternate:
166
+ test_alternate_is_used .git/modules/subwithsub/objects/info/alternates subwithsub &&
167
+ # but nested submodule has no alternate:
168
+ test_must_fail test_alternate_is_used .git/modules/subwithsub/modules/sub/objects/info/alternates subwithsub/sub
169
+}
170
+
171
+
172
+test_expect_success 'missing nested submodule alternate fails clone and submodule update' '
173
+ test_when_finished "rm -rf supersuper-clone" &&
174
+ test_must_fail git clone --recursive --reference supersuper2 supersuper2 supersuper-clone &&
175
+ (
176
+ cd supersuper-clone &&
177
+ check_that_two_of_three_alternates_are_used &&
178
+ # update of the submodule fails
179
+ test_must_fail git submodule update --init --recursive
180
+ )
181
+'
182
+
183
+test_expect_success 'missing nested submodule alternate in --reference-if-able mode' '
184
+ test_when_finished "rm -rf supersuper-clone" &&
185
+ git clone --recursive --reference-if-able supersuper2 supersuper2 supersuper-clone &&
186
+ (
187
+ cd supersuper-clone &&
188
+ check_that_two_of_three_alternates_are_used &&
189
+ # update of the submodule succeeds
190
+ git submodule update --init --recursive
191
+ )
192
+'
193
+
194
test_done