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 'preparing first repository' '
26 git commit -m A-initial
30 test_expect_success 'preparing second repository' '
36 git commit -m B-addition &&
42 test_expect_success 'preparing superproject' '
43 test_create_repo super &&
48 git commit -m B-super-initial
52 test_expect_success 'submodule add --reference uses alternates' '
55 git submodule add --reference ../B "file://$base_dir/A" sub &&
56 git commit -m B-super-added &&
59 test_alternate_is_used super/.git/modules/sub/objects/info/alternates super/sub
62 test_expect_success 'that reference gets used with add' '
65 echo "0 objects, 0 kilobytes" >expected &&
66 git count-objects >current &&
71 # The tests up to this point, and repositories created by them
72 # (A, B, super and super/sub), are about setting up the stage
73 # for subsequent tests and meant to be kept throughout the
74 # remainder of the test.
75 # Tests from here on, if they create their own test repository,
76 # are expected to clean after themselves.
78 test_expect_success 'updating superproject keeps alternates' '
79 test_when_finished "rm -rf super-clone" &&
80 git clone super super-clone &&
81 git -C super-clone submodule update --init --reference ../B &&
82 test_alternate_is_used super-clone/.git/modules/sub/objects/info/alternates super-clone/sub
85 test_expect_success 'submodules use alternates when cloning a superproject' '
86 test_when_finished "rm -rf super-clone" &&
87 git clone --reference super --recursive super super-clone &&
90 # test superproject has alternates setup correctly
91 test_alternate_is_used .git/objects/info/alternates . &&
92 # test submodule has correct setup
93 test_alternate_is_used .git/modules/sub/objects/info/alternates sub
97 test_expect_success 'missing submodule alternate fails clone and submodule update' '
98 test_when_finished "rm -rf super-clone" &&
99 git clone super super2 &&
100 test_must_fail git clone --recursive --reference super2 super2 super-clone &&
103 # test superproject has alternates setup correctly
104 test_alternate_is_used .git/objects/info/alternates . &&
105 # update of the submodule succeeds
106 test_must_fail git submodule update --init &&
107 # and we have no alternates:
108 test_must_fail test_alternate_is_used .git/modules/sub/objects/info/alternates sub &&
109 test_must_fail test_path_is_file sub/file1
113 test_expect_success 'ignoring missing submodule alternates passes clone and submodule update' '
114 test_when_finished "rm -rf super-clone" &&
115 git clone --reference-if-able super2 --recursive super2 super-clone &&
118 # test superproject has alternates setup correctly
119 test_alternate_is_used .git/objects/info/alternates . &&
120 # update of the submodule succeeds
121 git submodule update --init &&
122 # and we have no alternates:
123 test_must_fail test_alternate_is_used .git/modules/sub/objects/info/alternates sub &&
124 test_path_is_file sub/file1