builtin/blame.c: remove '--indent-heuristic' from usage string
[git/debian.git] / t / t7408-submodule-reference.sh
blob34ac28c056bbe8c80178082c770f392bff333fa7
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 'preparing first repository' '
21 test_create_repo A &&
23 cd A &&
24 echo first >file1 &&
25 git add file1 &&
26 git commit -m A-initial
30 test_expect_success 'preparing second repository' '
31 git clone A B &&
33 cd B &&
34 echo second >file2 &&
35 git add file2 &&
36 git commit -m B-addition &&
37 git repack -a -d &&
38 git prune
42 test_expect_success 'preparing superproject' '
43 test_create_repo super &&
45 cd super &&
46 echo file >file &&
47 git add file &&
48 git commit -m B-super-initial
52 test_expect_success 'submodule add --reference uses alternates' '
54 cd super &&
55 git submodule add --reference ../B "file://$base_dir/A" sub &&
56 git commit -m B-super-added &&
57 git repack -ad
58 ) &&
59 test_alternate_is_used super/.git/modules/sub/objects/info/alternates super/sub
62 test_expect_success 'submodule add --reference with --dissociate does not use alternates' '
64 cd super &&
65 git submodule add --reference ../B --dissociate "file://$base_dir/A" sub-dissociate &&
66 git commit -m B-super-added &&
67 git repack -ad
68 ) &&
69 test_path_is_missing super/.git/modules/sub-dissociate/objects/info/alternates
72 test_expect_success 'that reference gets used with add' '
74 cd super/sub &&
75 echo "0 objects, 0 kilobytes" >expected &&
76 git count-objects >current &&
77 diff expected current
81 # The tests up to this point, and repositories created by them
82 # (A, B, super and super/sub), are about setting up the stage
83 # for subsequent tests and meant to be kept throughout the
84 # remainder of the test.
85 # Tests from here on, if they create their own test repository,
86 # are expected to clean after themselves.
88 test_expect_success 'updating superproject keeps alternates' '
89 test_when_finished "rm -rf super-clone" &&
90 git clone super super-clone &&
91 git -C super-clone submodule update --init --reference ../B &&
92 test_alternate_is_used super-clone/.git/modules/sub/objects/info/alternates super-clone/sub
95 test_expect_success 'updating superproject with --dissociate does not keep alternates' '
96 test_when_finished "rm -rf super-clone" &&
97 git clone super super-clone &&
98 git -C super-clone submodule update --init --reference ../B --dissociate &&
99 test_path_is_missing super-clone/.git/modules/sub/objects/info/alternates
102 test_expect_success 'submodules use alternates when cloning a superproject' '
103 test_when_finished "rm -rf super-clone" &&
104 git clone --reference super --recursive super super-clone &&
106 cd super-clone &&
107 # test superproject has alternates setup correctly
108 test_alternate_is_used .git/objects/info/alternates . &&
109 # test submodule has correct setup
110 test_alternate_is_used .git/modules/sub/objects/info/alternates sub
114 test_expect_success 'missing submodule alternate fails clone and submodule update' '
115 test_when_finished "rm -rf super-clone" &&
116 git clone super super2 &&
117 test_must_fail git clone --recursive --reference super2 super2 super-clone &&
119 cd super-clone &&
120 # test superproject has alternates setup correctly
121 test_alternate_is_used .git/objects/info/alternates . &&
122 # update of the submodule succeeds
123 test_must_fail git submodule update --init &&
124 # and we have no alternates:
125 test_must_fail test_alternate_is_used .git/modules/sub/objects/info/alternates sub &&
126 test_must_fail test_path_is_file sub/file1
130 test_expect_success 'ignoring missing submodule alternates passes clone and submodule update' '
131 test_when_finished "rm -rf super-clone" &&
132 git clone --reference-if-able super2 --recursive super2 super-clone &&
134 cd super-clone &&
135 # test superproject has alternates setup correctly
136 test_alternate_is_used .git/objects/info/alternates . &&
137 # update of the submodule succeeds
138 git submodule update --init &&
139 # and we have no alternates:
140 test_must_fail test_alternate_is_used .git/modules/sub/objects/info/alternates sub &&
141 test_path_is_file sub/file1
145 test_expect_success 'preparing second superproject with a nested submodule plus partial clone' '
146 test_create_repo supersuper &&
148 cd supersuper &&
149 echo "I am super super." >file &&
150 git add file &&
151 git commit -m B-super-super-initial &&
152 git submodule add "file://$base_dir/super" subwithsub &&
153 git commit -m B-super-super-added &&
154 git submodule update --init --recursive &&
155 git repack -ad
156 ) &&
157 git clone supersuper supersuper2 &&
159 cd supersuper2 &&
160 git submodule update --init
164 # At this point there are three root-level positories: A, B, super and super2
166 test_expect_success 'nested submodule alternate in works and is actually used' '
167 test_when_finished "rm -rf supersuper-clone" &&
168 git clone --recursive --reference supersuper supersuper supersuper-clone &&
170 cd supersuper-clone &&
171 # test superproject has alternates setup correctly
172 test_alternate_is_used .git/objects/info/alternates . &&
173 # immediate submodule has alternate:
174 test_alternate_is_used .git/modules/subwithsub/objects/info/alternates subwithsub &&
175 # nested submodule also has alternate:
176 test_alternate_is_used .git/modules/subwithsub/modules/sub/objects/info/alternates subwithsub/sub
180 check_that_two_of_three_alternates_are_used() {
181 test_alternate_is_used .git/objects/info/alternates . &&
182 # immediate submodule has alternate:
183 test_alternate_is_used .git/modules/subwithsub/objects/info/alternates subwithsub &&
184 # but nested submodule has no alternate:
185 test_must_fail test_alternate_is_used .git/modules/subwithsub/modules/sub/objects/info/alternates subwithsub/sub
189 test_expect_success 'missing nested submodule alternate fails clone and submodule update' '
190 test_when_finished "rm -rf supersuper-clone" &&
191 test_must_fail git clone --recursive --reference supersuper2 supersuper2 supersuper-clone &&
193 cd supersuper-clone &&
194 check_that_two_of_three_alternates_are_used &&
195 # update of the submodule fails
196 test_must_fail git submodule update --init --recursive
200 test_expect_success 'missing nested submodule alternate in --reference-if-able mode' '
201 test_when_finished "rm -rf supersuper-clone" &&
202 git clone --recursive --reference-if-able supersuper2 supersuper2 supersuper-clone &&
204 cd supersuper-clone &&
205 check_that_two_of_three_alternates_are_used &&
206 # update of the submodule succeeds
207 git submodule update --init --recursive
211 test_done