1#!/bin/sh
2# Copyright (c) 2006, Junio C Hamano.
34
test_description='Per branch config variables affects "git fetch".
56
'
78
. ./test-lib.sh
910
D=`pwd`
1112
test_expect_success setup '
13echo >file original &&
14git add file &&
15git commit -a -m original'
1617
test_expect_success "clone and setup child repos" '
18git clone . one &&
19cd one &&
20echo >file updated by one &&
21git commit -a -m "updated by one" &&
22cd .. &&
23git clone . two &&
24cd two &&
25git config branch.master.remote one &&
26git config remote.one.url ../one/.git/ &&
27git config remote.one.fetch refs/heads/master:refs/heads/one &&
28cd .. &&
29git clone . three &&
30cd three &&
31git config branch.master.remote two &&
32git config branch.master.merge refs/heads/one &&
33mkdir -p .git/remotes &&
34{
35echo "URL: ../two/.git/"
36echo "Pull: refs/heads/master:refs/heads/two"
37echo "Pull: refs/heads/one:refs/heads/one"
38} >.git/remotes/two &&
39cd .. &&
40git clone . bundle
41'
4243
test_expect_success "fetch test" '
44cd "$D" &&
45echo >file updated by origin &&
46git commit -a -m "updated by origin" &&
47cd two &&
48git fetch &&
49test -f .git/refs/heads/one &&
50mine=`git rev-parse refs/heads/one` &&
51his=`cd ../one && git rev-parse refs/heads/master` &&
52test "z$mine" = "z$his"
53'
5455
test_expect_success "fetch test for-merge" '
56cd "$D" &&
57cd three &&
58git fetch &&
59test -f .git/refs/heads/two &&
60test -f .git/refs/heads/one &&
61master_in_two=`cd ../two && git rev-parse master` &&
62one_in_two=`cd ../two && git rev-parse one` &&
63{
64echo "$master_in_two not-for-merge"
65echo "$one_in_two "
66} >expected &&
67cut -f -2 .git/FETCH_HEAD >actual &&
68diff expected actual'
6970
test_expect_success 'fetch tags when there is no tags' '
7172
cd "$D" &&
7374
mkdir notags &&
75cd notags &&
76git init &&
7778
git fetch -t ..
7980
'
8182
test_expect_success 'fetch following tags' '
8384
cd "$D" &&
85git tag -a -m 'annotated' anno HEAD &&
86git tag light HEAD &&
8788
mkdir four &&
89cd four &&
90git init &&
9192
git fetch .. :track &&
93git show-ref --verify refs/tags/anno &&
94git show-ref --verify refs/tags/light
9596
'
9798
test_expect_success 'create bundle 1' '
99cd "$D" &&
100echo >file updated again by origin &&
101git commit -a -m "tip" &&
102git bundle create bundle1 master^..master
103'
104105
test_expect_success 'header of bundle looks right' '
106head -n 1 "$D"/bundle1 | grep "^#" &&
107head -n 2 "$D"/bundle1 | grep "^-[0-9a-f]\{40\} " &&
108head -n 3 "$D"/bundle1 | grep "^[0-9a-f]\{40\} " &&
109head -n 4 "$D"/bundle1 | grep "^$"
110'
111112
test_expect_success 'create bundle 2' '
113cd "$D" &&
114git bundle create bundle2 master~2..master
115'
116117
test_expect_failure 'unbundle 1' '
118cd "$D/bundle" &&
119git checkout -b some-branch &&
120git fetch "$D/bundle1" master:master
121'
122123
test_expect_success 'bundle 1 has only 3 files ' '
124cd "$D" &&
125(
126while read x && test -n "$x"
127do
128:;
129done
130cat
131) <bundle1 >bundle.pack &&
132git index-pack bundle.pack &&
133verify=$(git verify-pack -v bundle.pack) &&
134test 4 = $(echo "$verify" | wc -l)
135'
136137
test_expect_success 'unbundle 2' '
138cd "$D/bundle" &&
139git fetch ../bundle2 master:master &&
140test "tip" = "$(git log -1 --pretty=oneline master | cut -b42-)"
141'
142143
test_expect_success 'bundle does not prerequisite objects' '
144cd "$D" &&
145touch file2 &&
146git add file2 &&
147git commit -m add.file2 file2 &&
148git bundle create bundle3 -1 HEAD &&
149(
150while read x && test -n "$x"
151do
152:;
153done
154cat
155) <bundle3 >bundle.pack &&
156git index-pack bundle.pack &&
157test 4 = $(git verify-pack -v bundle.pack | wc -l)
158'
159160
test_expect_success 'bundle should be able to create a full history' '
161162
cd "$D" &&
163git tag -a -m '1.0' v1.0 master &&
164git bundle create bundle4 v1.0
165166
'
167168
test "$TEST_RSYNC" && {
169test_expect_success 'fetch via rsync' '
170git pack-refs &&
171mkdir rsynced &&
172cd rsynced &&
173git init &&
174git fetch rsync://127.0.0.1$(pwd)/../.git master:refs/heads/master &&
175git gc --prune &&
176test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
177git fsck --full
178'
179180
test_expect_success 'push via rsync' '
181mkdir ../rsynced2 &&
182(cd ../rsynced2 &&
183git init) &&
184git push rsync://127.0.0.1$(pwd)/../rsynced2/.git master &&
185cd ../rsynced2 &&
186git gc --prune &&
187test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
188git fsck --full
189'
190191
test_expect_success 'push via rsync' '
192cd .. &&
193mkdir rsynced3 &&
194(cd rsynced3 &&
195git init) &&
196git push --all rsync://127.0.0.1$(pwd)/rsynced3/.git &&
197cd rsynced3 &&
198test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
199git fsck --full
200'
201}
202203
test_done