Start the 2.48 cycle
[git/gitster.git] / t / t7408-submodule-reference.sh
blob7e1afa9ce470b14dc050eed0b23610b38b6a61bc
1 #!/bin/sh
3 # Copyright (c) 2009, Red Hat Inc, Author: Michael S. Tsirkin (mst@redhat.com)
6 test_description='test clone --reference'
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 base_dir=$(pwd)
13 test_alternate_is_used () {
14 alternates_file="$1" &&
15 working_dir="$2" &&
16 test_line_count = 1 "$alternates_file" &&
17 echo "0 objects, 0 kilobytes" >expect &&
18 git -C "$working_dir" count-objects >actual &&
19 test_cmp expect actual
22 test_expect_success 'setup' '
23 git config --global protocol.file.allow always
26 test_expect_success 'preparing first repository' '
27 test_create_repo A &&
29 cd A &&
30 echo first >file1 &&
31 git add file1 &&
32 git commit -m A-initial
36 test_expect_success 'preparing second repository' '
37 git clone A B &&
39 cd B &&
40 echo second >file2 &&
41 git add file2 &&
42 git commit -m B-addition &&
43 git repack -a -d &&
44 git prune
48 test_expect_success 'preparing superproject' '
49 test_create_repo super &&
51 cd super &&
52 echo file >file &&
53 git add file &&
54 git commit -m B-super-initial
58 test_expect_success 'submodule add --reference uses alternates' '
60 cd super &&
61 git submodule add --reference ../B "file://$base_dir/A" sub &&
62 git commit -m B-super-added &&
63 git repack -ad
64 ) &&
65 test_alternate_is_used super/.git/modules/sub/objects/info/alternates super/sub
68 test_expect_success 'submodule add --reference with --dissociate does not use alternates' '
70 cd super &&
71 git submodule add --reference ../B --dissociate "file://$base_dir/A" sub-dissociate &&
72 git commit -m B-super-added &&
73 git repack -ad
74 ) &&
75 test_path_is_missing super/.git/modules/sub-dissociate/objects/info/alternates
78 test_expect_success 'that reference gets used with add' '
80 cd super/sub &&
81 echo "0 objects, 0 kilobytes" >expected &&
82 git count-objects >current &&
83 diff expected current
87 # The tests up to this point, and repositories created by them
88 # (A, B, super and super/sub), are about setting up the stage
89 # for subsequent tests and meant to be kept throughout the
90 # remainder of the test.
91 # Tests from here on, if they create their own test repository,
92 # are expected to clean after themselves.
94 test_expect_success 'updating superproject keeps alternates' '
95 test_when_finished "rm -rf super-clone" &&
96 git clone super super-clone &&
97 git -C super-clone submodule update --init --reference ../B &&
98 test_alternate_is_used super-clone/.git/modules/sub/objects/info/alternates super-clone/sub
101 test_expect_success 'updating superproject with --dissociate does not keep alternates' '
102 test_when_finished "rm -rf super-clone" &&
103 git clone super super-clone &&
104 git -C super-clone submodule update --init --reference ../B --dissociate &&
105 test_path_is_missing super-clone/.git/modules/sub/objects/info/alternates
108 test_expect_success 'submodules use alternates when cloning a superproject' '
109 test_when_finished "rm -rf super-clone" &&
110 git clone --reference super --recursive super super-clone &&
112 cd super-clone &&
113 # test superproject has alternates setup correctly
114 test_alternate_is_used .git/objects/info/alternates . &&
115 # test submodule has correct setup
116 test_alternate_is_used .git/modules/sub/objects/info/alternates sub
120 test_expect_success 'missing submodule alternate fails clone and submodule update' '
121 test_when_finished "rm -rf super-clone" &&
122 git clone super super2 &&
123 test_must_fail git clone --recursive --reference super2 super2 super-clone &&
125 cd super-clone &&
126 # test superproject has alternates setup correctly
127 test_alternate_is_used .git/objects/info/alternates . &&
128 # update of the submodule succeeds
129 test_must_fail git submodule update --init &&
130 # and we have no alternates:
131 test_path_is_missing .git/modules/sub/objects/info/alternates &&
132 test_path_is_missing sub/file1
136 test_expect_success 'ignoring missing submodule alternates passes clone and submodule update' '
137 test_when_finished "rm -rf super-clone" &&
138 git clone --reference-if-able super2 --recursive super2 super-clone &&
140 cd super-clone &&
141 # test superproject has alternates setup correctly
142 test_alternate_is_used .git/objects/info/alternates . &&
143 # update of the submodule succeeds
144 git submodule update --init &&
145 # and we have no alternates:
146 test_path_is_missing .git/modules/sub/objects/info/alternates &&
147 test_path_is_file sub/file1
151 test_expect_success 'preparing second superproject with a nested submodule plus partial clone' '
152 test_create_repo supersuper &&
154 cd supersuper &&
155 echo "I am super super." >file &&
156 git add file &&
157 git commit -m B-super-super-initial &&
158 git submodule add "file://$base_dir/super" subwithsub &&
159 git commit -m B-super-super-added &&
160 git submodule update --init --recursive &&
161 git repack -ad
162 ) &&
163 git clone supersuper supersuper2 &&
165 cd supersuper2 &&
166 git submodule update --init
170 # At this point there are three root-level positories: A, B, super and super2
172 test_expect_success 'nested submodule alternate in works and is actually used' '
173 test_when_finished "rm -rf supersuper-clone" &&
174 git clone --recursive --reference supersuper supersuper supersuper-clone &&
176 cd supersuper-clone &&
177 # test superproject has alternates setup correctly
178 test_alternate_is_used .git/objects/info/alternates . &&
179 # immediate submodule has alternate:
180 test_alternate_is_used .git/modules/subwithsub/objects/info/alternates subwithsub &&
181 # nested submodule also has alternate:
182 test_alternate_is_used .git/modules/subwithsub/modules/sub/objects/info/alternates subwithsub/sub
186 check_that_two_of_three_alternates_are_used() {
187 test_alternate_is_used .git/objects/info/alternates . &&
188 # immediate submodule has alternate:
189 test_alternate_is_used .git/modules/subwithsub/objects/info/alternates subwithsub &&
190 # but nested submodule has no alternate:
191 test_path_is_missing .git/modules/subwithsub/modules/sub/objects/info/alternates
195 test_expect_success 'missing nested submodule alternate fails clone and submodule update' '
196 test_when_finished "rm -rf supersuper-clone" &&
197 test_must_fail git clone --recursive --reference supersuper2 supersuper2 supersuper-clone &&
199 cd supersuper-clone &&
200 check_that_two_of_three_alternates_are_used &&
201 # update of the submodule fails
202 cat >expect <<-\EOF &&
203 fatal: submodule '\''sub'\'' cannot add alternate: path ... does not exist
204 Failed to clone '\''sub'\''. Retry scheduled
205 fatal: submodule '\''sub-dissociate'\'' cannot add alternate: path ... does not exist
206 Failed to clone '\''sub-dissociate'\''. Retry scheduled
207 fatal: submodule '\''sub'\'' cannot add alternate: path ... does not exist
208 Failed to clone '\''sub'\'' a second time, aborting
209 fatal: Failed to recurse into submodule path ...
211 test_must_fail git submodule update --init --recursive 2>err &&
212 grep -e fatal: -e ^Failed err >actual.raw &&
213 sed -e "s/path $SQ[^$SQ]*$SQ/path .../" <actual.raw >actual &&
214 test_cmp expect actual
218 test_expect_success 'missing nested submodule alternate in --reference-if-able mode' '
219 test_when_finished "rm -rf supersuper-clone" &&
220 git clone --recursive --reference-if-able supersuper2 supersuper2 supersuper-clone &&
222 cd supersuper-clone &&
223 check_that_two_of_three_alternates_are_used &&
224 # update of the submodule succeeds
225 git submodule update --init --recursive
229 test_done