1#!/bin/sh
2#
3# Copyright (C) 2006 Martin Waitz <tali@admingilde.org>
4#
5
6test_description='test clone --reference'
7. ./test-lib.sh
8
9base_dir=`pwd`
10
11U=$base_dir/UPLOAD_LOG
12
13test_expect_success 'preparing first repository' \
14'test_create_repo A && cd A &&
15echo first > file1 &&
16git add file1 &&
17git commit -m initial'
18
19cd "$base_dir"
20
21test_expect_success 'preparing second repository' \
22'git clone A B && cd B &&
23echo second > file2 &&
24git add file2 &&
25git commit -m addition &&
26git repack -a -d &&
27git prune'
28
29cd "$base_dir"
30
31test_expect_success 'cloning with reference (-l -s)' \
32'git clone -l -s --reference B A C'
33
34cd "$base_dir"
35
36test_expect_success 'existence of info/alternates' \
37'test_line_count = 2 C/.git/objects/info/alternates'
38
39cd "$base_dir"
40
41test_expect_success 'pulling from reference' \
42'cd C &&
43git pull ../B master'
44
45cd "$base_dir"
46
47test_expect_success 'that reference gets used' \
48'cd C &&
49echo "0 objects, 0 kilobytes" > expected &&
50git count-objects > current &&
51test_cmp expected current'
52
53cd "$base_dir"
54
55rm -f "$U.D"
56
57test_expect_success 'cloning with reference (no -l -s)' \
58'GIT_DEBUG_SEND_PACK=3 git clone --reference B "file://$(pwd)/A" D 3>"$U.D"'
59
60test_expect_success 'fetched no objects' \
61'! grep "^want" "$U.D"'
62
63cd "$base_dir"
64
65test_expect_success 'existence of info/alternates' \
66'test_line_count = 1 D/.git/objects/info/alternates'
67
68cd "$base_dir"
69
70test_expect_success 'pulling from reference' \
71'cd D && git pull ../B master'
72
73cd "$base_dir"
74
75test_expect_success 'that reference gets used' \
76'cd D && echo "0 objects, 0 kilobytes" > expected &&
77git count-objects > current &&
78test_cmp expected current'
79
80cd "$base_dir"
81
82test_expect_success 'updating origin' \
83'cd A &&
84echo third > file3 &&
85git add file3 &&
86git commit -m update &&
87git repack -a -d &&
88git prune'
89
90cd "$base_dir"
91
92test_expect_success 'pulling changes from origin' \
93'cd C &&
94git pull origin'
95
96cd "$base_dir"
97
98# the 2 local objects are commit and tree from the merge
99test_expect_success 'that alternate to origin gets used' \
100'cd C &&
101echo "2 objects" > expected &&
102git count-objects | cut -d, -f1 > current &&
103test_cmp expected current'
104
105cd "$base_dir"
106
107test_expect_success 'pulling changes from origin' \
108'cd D &&
109git pull origin'
110
111cd "$base_dir"
112
113# the 5 local objects are expected; file3 blob, commit in A to add it
114# and its tree, and 2 are our tree and the merge commit.
115test_expect_success 'check objects expected to exist locally' \
116'cd D &&
117echo "5 objects" > expected &&
118git count-objects | cut -d, -f1 > current &&
119test_cmp expected current'
120
121cd "$base_dir"
122
123test_expect_success 'preparing alternate repository #1' \
124'test_create_repo F && cd F &&
125echo first > file1 &&
126git add file1 &&
127git commit -m initial'
128
129cd "$base_dir"
130
131test_expect_success 'cloning alternate repo #2 and adding changes to repo #1' \
132'git clone F G && cd F &&
133echo second > file2 &&
134git add file2 &&
135git commit -m addition'
136
137cd "$base_dir"
138
139test_expect_success 'cloning alternate repo #1, using #2 as reference' \
140'git clone --reference G F H'
141
142cd "$base_dir"
143
144test_expect_success 'cloning with reference being subset of source (-l -s)' \
145'git clone -l -s --reference A B E'
146
147cd "$base_dir"
148
149test_expect_success 'clone with reference from a tagged repository' '
150 (
151 cd A && git tag -a -m 'tagged' HEAD
152 ) &&
153 git clone --reference=A A I
154'
155
156test_expect_success 'prepare branched repository' '
157 git clone A J &&
158 (
159 cd J &&
160 git checkout -b other master^ &&
161 echo other >otherfile &&
162 git add otherfile &&
163 git commit -m other &&
164 git checkout master
165 )
166'
167
168rm -f "$U.K"
169
170test_expect_success 'fetch with incomplete alternates' '
171 git init K &&
172 echo "$base_dir/A/.git/objects" >K/.git/objects/info/alternates &&
173 (
174 cd K &&
175 git remote add J "file://$base_dir/J" &&
176 GIT_DEBUG_SEND_PACK=3 git fetch J 3>"$U.K"
177 ) &&
178 master_object=$(cd A && git for-each-ref --format="%(objectname)" refs/heads/master) &&
179 ! grep "^want $master_object" "$U.K" &&
180 tag_object=$(cd A && git for-each-ref --format="%(objectname)" refs/tags/HEAD) &&
181 ! grep "^want $tag_object" "$U.K"
182'
183
184test_done