]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7408-submodule-reference.sh
The third batch
[thirdparty/git.git] / t / t7408-submodule-reference.sh
CommitLineData
d92a3959
MT
1#!/bin/sh
2#
3# Copyright (c) 2009, Red Hat Inc, Author: Michael S. Tsirkin (mst@redhat.com)
4#
5
6test_description='test clone --reference'
7. ./test-lib.sh
8
db0ff2c0 9base_dir=$(pwd)
d92a3959 10
9292536e
SB
11test_alternate_is_used () {
12 alternates_file="$1" &&
13 working_dir="$2" &&
14 test_line_count = 1 "$alternates_file" &&
15 echo "0 objects, 0 kilobytes" >expect &&
16 git -C "$working_dir" count-objects >actual &&
17 test_cmp expect actual
18}
19
0d3beb71
TB
20test_expect_success 'setup' '
21 git config --global protocol.file.allow always
22'
23
83dec733
SB
24test_expect_success 'preparing first repository' '
25 test_create_repo A &&
26 (
27 cd A &&
28 echo first >file1 &&
29 git add file1 &&
30 git commit -m A-initial
31 )
32'
33
34test_expect_success 'preparing second repository' '
35 git clone A B &&
36 (
37 cd B &&
38 echo second >file2 &&
39 git add file2 &&
40 git commit -m B-addition &&
41 git repack -a -d &&
42 git prune
43 )
44'
45
46test_expect_success 'preparing superproject' '
47 test_create_repo super &&
48 (
49 cd super &&
50 echo file >file &&
51 git add file &&
52 git commit -m B-super-initial
53 )
54'
55
9292536e 56test_expect_success 'submodule add --reference uses alternates' '
83dec733
SB
57 (
58 cd super &&
59 git submodule add --reference ../B "file://$base_dir/A" sub &&
9292536e
SB
60 git commit -m B-super-added &&
61 git repack -ad
62 ) &&
63 test_alternate_is_used super/.git/modules/sub/objects/info/alternates super/sub
83dec733
SB
64'
65
a0ef2934
CF
66test_expect_success 'submodule add --reference with --dissociate does not use alternates' '
67 (
68 cd super &&
69 git submodule add --reference ../B --dissociate "file://$base_dir/A" sub-dissociate &&
70 git commit -m B-super-added &&
71 git repack -ad
72 ) &&
73 test_path_is_missing super/.git/modules/sub-dissociate/objects/info/alternates
74'
75
83dec733
SB
76test_expect_success 'that reference gets used with add' '
77 (
78 cd super/sub &&
79 echo "0 objects, 0 kilobytes" >expected &&
80 git count-objects >current &&
81 diff expected current
82 )
83'
84
9292536e
SB
85# The tests up to this point, and repositories created by them
86# (A, B, super and super/sub), are about setting up the stage
87# for subsequent tests and meant to be kept throughout the
88# remainder of the test.
89# Tests from here on, if they create their own test repository,
90# are expected to clean after themselves.
83dec733 91
9292536e
SB
92test_expect_success 'updating superproject keeps alternates' '
93 test_when_finished "rm -rf super-clone" &&
94 git clone super super-clone &&
95 git -C super-clone submodule update --init --reference ../B &&
96 test_alternate_is_used super-clone/.git/modules/sub/objects/info/alternates super-clone/sub
83dec733 97'
d92a3959 98
a0ef2934
CF
99test_expect_success 'updating superproject with --dissociate does not keep alternates' '
100 test_when_finished "rm -rf super-clone" &&
101 git clone super super-clone &&
102 git -C super-clone submodule update --init --reference ../B --dissociate &&
103 test_path_is_missing super-clone/.git/modules/sub/objects/info/alternates
104'
105
31224cbd
SB
106test_expect_success 'submodules use alternates when cloning a superproject' '
107 test_when_finished "rm -rf super-clone" &&
108 git clone --reference super --recursive super super-clone &&
109 (
110 cd super-clone &&
111 # test superproject has alternates setup correctly
112 test_alternate_is_used .git/objects/info/alternates . &&
113 # test submodule has correct setup
114 test_alternate_is_used .git/modules/sub/objects/info/alternates sub
115 )
116'
117
118test_expect_success 'missing submodule alternate fails clone and submodule update' '
119 test_when_finished "rm -rf super-clone" &&
120 git clone super super2 &&
121 test_must_fail git clone --recursive --reference super2 super2 super-clone &&
122 (
123 cd super-clone &&
124 # test superproject has alternates setup correctly
125 test_alternate_is_used .git/objects/info/alternates . &&
126 # update of the submodule succeeds
127 test_must_fail git submodule update --init &&
128 # and we have no alternates:
4cf795b8
DL
129 test_path_is_missing .git/modules/sub/objects/info/alternates &&
130 test_path_is_missing sub/file1
31224cbd
SB
131 )
132'
133
134test_expect_success 'ignoring missing submodule alternates passes clone and submodule update' '
135 test_when_finished "rm -rf super-clone" &&
136 git clone --reference-if-able super2 --recursive super2 super-clone &&
137 (
138 cd super-clone &&
139 # test superproject has alternates setup correctly
140 test_alternate_is_used .git/objects/info/alternates . &&
141 # update of the submodule succeeds
142 git submodule update --init &&
143 # and we have no alternates:
4cf795b8 144 test_path_is_missing .git/modules/sub/objects/info/alternates &&
31224cbd
SB
145 test_path_is_file sub/file1
146 )
147'
148
bf03b790
VS
149test_expect_success 'preparing second superproject with a nested submodule plus partial clone' '
150 test_create_repo supersuper &&
151 (
152 cd supersuper &&
153 echo "I am super super." >file &&
154 git add file &&
e974e06d 155 git commit -m B-super-super-initial &&
bf03b790
VS
156 git submodule add "file://$base_dir/super" subwithsub &&
157 git commit -m B-super-super-added &&
158 git submodule update --init --recursive &&
159 git repack -ad
160 ) &&
161 git clone supersuper supersuper2 &&
162 (
163 cd supersuper2 &&
164 git submodule update --init
165 )
166'
167
168# At this point there are three root-level positories: A, B, super and super2
169
170test_expect_success 'nested submodule alternate in works and is actually used' '
171 test_when_finished "rm -rf supersuper-clone" &&
172 git clone --recursive --reference supersuper supersuper supersuper-clone &&
173 (
174 cd supersuper-clone &&
175 # test superproject has alternates setup correctly
176 test_alternate_is_used .git/objects/info/alternates . &&
177 # immediate submodule has alternate:
178 test_alternate_is_used .git/modules/subwithsub/objects/info/alternates subwithsub &&
179 # nested submodule also has alternate:
180 test_alternate_is_used .git/modules/subwithsub/modules/sub/objects/info/alternates subwithsub/sub
181 )
182'
183
184check_that_two_of_three_alternates_are_used() {
185 test_alternate_is_used .git/objects/info/alternates . &&
186 # immediate submodule has alternate:
187 test_alternate_is_used .git/modules/subwithsub/objects/info/alternates subwithsub &&
188 # but nested submodule has no alternate:
4cf795b8 189 test_path_is_missing .git/modules/subwithsub/modules/sub/objects/info/alternates
bf03b790
VS
190}
191
192
193test_expect_success 'missing nested submodule alternate fails clone and submodule update' '
194 test_when_finished "rm -rf supersuper-clone" &&
195 test_must_fail git clone --recursive --reference supersuper2 supersuper2 supersuper-clone &&
196 (
197 cd supersuper-clone &&
198 check_that_two_of_three_alternates_are_used &&
199 # update of the submodule fails
aca8568e
ÆAB
200 cat >expect <<-\EOF &&
201 fatal: submodule '\''sub'\'' cannot add alternate: path ... does not exist
202 Failed to clone '\''sub'\''. Retry scheduled
203 fatal: submodule '\''sub-dissociate'\'' cannot add alternate: path ... does not exist
204 Failed to clone '\''sub-dissociate'\''. Retry scheduled
205 fatal: submodule '\''sub'\'' cannot add alternate: path ... does not exist
206 Failed to clone '\''sub'\'' a second time, aborting
207 fatal: Failed to recurse into submodule path ...
208 EOF
209 test_must_fail git submodule update --init --recursive 2>err &&
210 grep -e fatal: -e ^Failed err >actual.raw &&
211 sed -e "s/path $SQ[^$SQ]*$SQ/path .../" <actual.raw >actual &&
212 test_cmp expect actual
bf03b790
VS
213 )
214'
215
216test_expect_success 'missing nested submodule alternate in --reference-if-able mode' '
217 test_when_finished "rm -rf supersuper-clone" &&
218 git clone --recursive --reference-if-able supersuper2 supersuper2 supersuper-clone &&
219 (
220 cd supersuper-clone &&
221 check_that_two_of_three_alternates_are_used &&
222 # update of the submodule succeeds
223 git submodule update --init --recursive
224 )
225'
226
d92a3959 227test_done