unit-tests: do not mistake `.pdb` files for being executable
[git.git] / t / t7408-submodule-reference.sh
blobd6040e0a33703310d52d588607e4f62912f0c049
1 #!/bin/sh
3 # Copyright (c) 2009, Red Hat Inc, Author: Michael S. Tsirkin (mst@redhat.com)
6 test_description='test clone --reference'
7 . ./test-lib.sh
9 base_dir=$(pwd)
11 test_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
20 test_expect_success 'setup' '
21 git config --global protocol.file.allow always
24 test_expect_success 'preparing first repository' '
25 test_create_repo A &&
27 cd A &&
28 echo first >file1 &&
29 git add file1 &&
30 git commit -m A-initial
34 test_expect_success 'preparing second repository' '
35 git clone A B &&
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
46 test_expect_success 'preparing superproject' '
47 test_create_repo super &&
49 cd super &&
50 echo file >file &&
51 git add file &&
52 git commit -m B-super-initial
56 test_expect_success 'submodule add --reference uses alternates' '
58 cd super &&
59 git submodule add --reference ../B "file://$base_dir/A" sub &&
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
66 test_expect_success 'submodule add --reference with --dissociate does not use alternates' '
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
76 test_expect_success 'that reference gets used with add' '
78 cd super/sub &&
79 echo "0 objects, 0 kilobytes" >expected &&
80 git count-objects >current &&
81 diff expected 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 &&
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
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 &&
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:
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 &&
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:
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 &&
152 cd supersuper &&
153 echo "I am super super." >file &&
154 git add 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 &&
159 git repack -ad
160 ) &&
161 git clone supersuper supersuper2 &&
163 cd 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 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 ...
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
216 test_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 &&
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
227 test_done