]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5700-clone-reference.sh
t5700: modernize style
[thirdparty/git.git] / t / t5700-clone-reference.sh
CommitLineData
cf9dc653
MW
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
4ba776c2
DB
11U=$base_dir/UPLOAD_LOG
12
bc192300
JK
13# create a commit in repo $1 with name $2
14commit_in () {
15 (
16 cd "$1" &&
17 echo "$2" >"$2" &&
18 git add "$2" &&
19 git commit -m "$2"
20 )
21}
22
23# check that there are $2 loose objects in repo $1
24test_objcount () {
25 echo "$2" >expect &&
26 git -C "$1" count-objects >actual.raw &&
27 cut -d' ' -f1 <actual.raw >actual &&
28 test_cmp expect actual
29}
30
31test_expect_success 'preparing first repository' '
32 test_create_repo A &&
33 commit_in A file1
34'
cf9dc653 35
bc192300
JK
36test_expect_success 'preparing second repository' '
37 git clone A B &&
38 commit_in B file2 &&
39 git -C B repack -ad &&
40 git -C B prune
41'
cf9dc653 42
bc192300
JK
43test_expect_success 'cloning with reference (-l -s)' '
44 git clone -l -s --reference B A C
45'
cf9dc653 46
bc192300
JK
47test_expect_success 'existence of info/alternates' '
48 test_line_count = 2 C/.git/objects/info/alternates
49'
cf9dc653 50
bc192300
JK
51test_expect_success 'pulling from reference' '
52 git -C C pull ../B master
53'
cf9dc653 54
bc192300
JK
55test_expect_success 'that reference gets used' '
56 test_objcount C 0
57'
4ba776c2 58
2ad23273
JK
59test_expect_success 'cloning with reference (no -l -s)' '
60 GIT_TRACE_PACKET=$U.D git clone --reference B "file://$(pwd)/A" D
61'
4ba776c2 62
2ad23273
JK
63test_expect_success 'fetched no objects' '
64 test -s "$U.D" &&
65 ! grep " want" "$U.D"
66'
1f7d1a53 67
bc192300
JK
68test_expect_success 'existence of info/alternates' '
69 test_line_count = 1 D/.git/objects/info/alternates
70'
1f7d1a53 71
bc192300
JK
72test_expect_success 'pulling from reference' '
73 git -C D pull ../B master
74'
cf9dc653 75
bc192300
JK
76test_expect_success 'that reference gets used' '
77 test_objcount D 0
78'
cf9dc653 79
bc192300
JK
80test_expect_success 'updating origin' '
81 commit_in A file3 &&
82 git -C A repack -ad &&
83 git -C A prune
84'
cf9dc653 85
bc192300
JK
86test_expect_success 'pulling changes from origin' '
87 git -C C pull origin
88'
cf9dc653
MW
89
90# the 2 local objects are commit and tree from the merge
bc192300
JK
91test_expect_success 'that alternate to origin gets used' '
92 test_objcount C 2
93'
1f7d1a53 94
bc192300
JK
95test_expect_success 'pulling changes from origin' '
96 git -C D pull origin
97'
1f7d1a53
JH
98
99# the 5 local objects are expected; file3 blob, commit in A to add it
100# and its tree, and 2 are our tree and the merge commit.
bc192300
JK
101test_expect_success 'check objects expected to exist locally' '
102 test_objcount D 5
103'
fabb0199 104
bc192300
JK
105test_expect_success 'preparing alternate repository #1' '
106 test_create_repo F &&
107 commit_in F file1
108'
fabb0199 109
bc192300
JK
110test_expect_success 'cloning alternate repo #2 and adding changes to repo #1' '
111 git clone F G &&
112 commit_in F file2
113'
fabb0199 114
bc192300
JK
115test_expect_success 'cloning alternate repo #1, using #2 as reference' '
116 git clone --reference G F H
117'
b50c8469 118
bc192300
JK
119test_expect_success 'cloning with reference being subset of source (-l -s)' '
120 git clone -l -s --reference A B E
121'
b50c8469 122
09116a1c
JH
123test_expect_success 'clone with reference from a tagged repository' '
124 (
bc192300 125 cd A && git tag -a -m tagged HEAD
09116a1c
JH
126 ) &&
127 git clone --reference=A A I
128'
129
acede2eb
MH
130test_expect_success 'prepare branched repository' '
131 git clone A J &&
132 (
133 cd J &&
134 git checkout -b other master^ &&
135 echo other >otherfile &&
136 git add otherfile &&
137 git commit -m other &&
138 git checkout master
139 )
140'
141
f2576591 142test_expect_success 'fetch with incomplete alternates' '
acede2eb
MH
143 git init K &&
144 echo "$base_dir/A/.git/objects" >K/.git/objects/info/alternates &&
145 (
146 cd K &&
147 git remote add J "file://$base_dir/J" &&
2ad23273 148 GIT_TRACE_PACKET=$U.K git fetch J
acede2eb
MH
149 ) &&
150 master_object=$(cd A && git for-each-ref --format="%(objectname)" refs/heads/master) &&
2ad23273 151 test -s "$U.K" &&
97a83fa8 152 ! grep " want $master_object" "$U.K" &&
acede2eb 153 tag_object=$(cd A && git for-each-ref --format="%(objectname)" refs/tags/HEAD) &&
97a83fa8 154 ! grep " want $tag_object" "$U.K"
acede2eb
MH
155'
156
b552b56d
AS
157test_expect_success 'clone using repo with gitfile as a reference' '
158 git clone --separate-git-dir=L A M &&
159 git clone --reference=M A N &&
160 echo "$base_dir/L/objects" >expected &&
161 test_cmp expected "$base_dir/N/.git/objects/info/alternates"
162'
163
164test_expect_success 'clone using repo pointed at by gitfile as reference' '
165 git clone --reference=M/.git A O &&
166 echo "$base_dir/L/objects" >expected &&
167 test_cmp expected "$base_dir/O/.git/objects/info/alternates"
168'
169
fb1d6dab
JH
170test_expect_success 'clone and dissociate from reference' '
171 git init P &&
172 (
173 cd P && test_commit one
174 ) &&
175 git clone P Q &&
176 (
177 cd Q && test_commit two
178 ) &&
179 git clone --no-local --reference=P Q R &&
180 git clone --no-local --reference=P --dissociate Q S &&
181 # removing the reference P would corrupt R but not S
182 rm -fr P &&
183 test_must_fail git -C R fsck &&
184 git -C S fsck
185'
186
cf9dc653 187test_done