3 # Copyright (c) 2009, Red Hat Inc, Author: Michael S. Tsirkin (mst@redhat.com)
6 test_description
='test clone --reference'
11 test_alternate_is_used
() {
12 alternates_file
="$1" &&
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
20 test_expect_success
'setup' '
21 git config --global protocol.file.allow always
24 test_expect_success
'preparing first repository' '
30 git commit -m A-initial
34 test_expect_success
'preparing second repository' '
40 git commit -m B-addition &&
46 test_expect_success
'preparing superproject' '
47 test_create_repo super &&
52 git commit -m B-super-initial
56 test_expect_success
'submodule add --reference uses alternates' '
59 git submodule add --reference ../B "file://$base_dir/A" sub &&
60 git commit -m B-super-added &&
63 test_alternate_is_used super/.git/modules/sub/objects/info/alternates super/sub
66 test_expect_success
'submodule add --reference with --dissociate does not use alternates' '
69 git submodule add --reference ../B --dissociate "file://$base_dir/A" sub-dissociate &&
70 git commit -m B-super-added &&
73 test_path_is_missing super/.git/modules/sub-dissociate/objects/info/alternates
76 test_expect_success
'that reference gets used with add' '
79 echo "0 objects, 0 kilobytes" >expected &&
80 git count-objects >current &&
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.
92 test_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
99 test_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
106 test_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 &&
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
118 test_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 &&
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:
129 test_path_is_missing .git/modules/sub/objects/info/alternates &&
130 test_path_is_missing sub/file1
134 test_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 &&
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:
144 test_path_is_missing .git/modules/sub/objects/info/alternates &&
145 test_path_is_file sub/file1
149 test_expect_success
'preparing second superproject with a nested submodule plus partial clone' '
150 test_create_repo supersuper &&
153 echo "I am super super." >file &&
155 git commit -m B-super-super-initial &&
156 git submodule add "file://$base_dir/super" subwithsub &&
157 git commit -m B-super-super-added &&
158 git submodule update --init --recursive &&
161 git clone supersuper supersuper2 &&
164 git submodule update --init
168 # At this point there are three root-level positories: A, B, super and super2
170 test_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 &&
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
184 check_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:
189 test_path_is_missing .git
/modules
/subwithsub
/modules
/sub
/objects
/info
/alternates
193 test_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 &&
197 cd supersuper-clone &&
198 check_that_two_of_three_alternates_are_used &&
199 # update of the submodule fails
200 test_must_fail git submodule update --init --recursive
204 test_expect_success
'missing nested submodule alternate in --reference-if-able mode' '
205 test_when_finished "rm -rf supersuper-clone" &&
206 git clone --recursive --reference-if-able supersuper2 supersuper2 supersuper-clone &&
208 cd supersuper-clone &&
209 check_that_two_of_three_alternates_are_used &&
210 # update of the submodule succeeds
211 git submodule update --init --recursive