dff47af2551bdc496ff5caeb1203dc303c178064
1#!/bin/sh
2#
3# Copyright (c) 2009, Red Hat Inc, Author: Michael S. Tsirkin (mst@redhat.com)
4#
5
6test_description='test clone --reference'
7. ./test-lib.sh
8
9base_dir=$(pwd)
10
11test_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
18}
19
20test_expect_success 'preparing first repository' '
21 test_create_repo A &&
22 (
23 cd A &&
24 echo first >file1 &&
25 git add file1 &&
26 git commit -m A-initial
27 )
28'
29
30test_expect_success 'preparing second repository' '
31 git clone A B &&
32 (
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
39 )
40'
41
42test_expect_success 'preparing superproject' '
43 test_create_repo super &&
44 (
45 cd super &&
46 echo file >file &&
47 git add file &&
48 git commit -m B-super-initial
49 )
50'
51
52test_expect_success 'submodule add --reference uses alternates' '
53 (
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
60'
61
62test_expect_success 'that reference gets used with add' '
63 (
64 cd super/sub &&
65 echo "0 objects, 0 kilobytes" >expected &&
66 git count-objects >current &&
67 diff expected current
68 )
69'
70
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.
77
78test_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
83'
84
85test_done