]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5510-fetch.sh
Fix a crash in ls-remote when refspec expands into nothing
[thirdparty/git.git] / t / t5510-fetch.sh
CommitLineData
7be1d62c
JH
1#!/bin/sh
2# Copyright (c) 2006, Junio C Hamano.
3
4test_description='Per branch config variables affects "git fetch".
5
6'
7
8. ./test-lib.sh
9
10D=`pwd`
11
12test_expect_success setup '
13 echo >file original &&
14 git add file &&
15 git commit -a -m original'
16
17test_expect_success "clone and setup child repos" '
18 git clone . one &&
19 cd one &&
20 echo >file updated by one &&
21 git commit -a -m "updated by one" &&
22 cd .. &&
23 git clone . two &&
24 cd two &&
e0d10e1c
TP
25 git config branch.master.remote one &&
26 git config remote.one.url ../one/.git/ &&
27 git config remote.one.fetch refs/heads/master:refs/heads/one &&
6cc7c36d
SB
28 cd .. &&
29 git clone . three &&
30 cd three &&
e0d10e1c
TP
31 git config branch.master.remote two &&
32 git config branch.master.merge refs/heads/one &&
75c384ef 33 mkdir -p .git/remotes &&
6cc7c36d
SB
34 {
35 echo "URL: ../two/.git/"
36 echo "Pull: refs/heads/master:refs/heads/two"
37 echo "Pull: refs/heads/one:refs/heads/one"
2e0afafe
JS
38 } >.git/remotes/two &&
39 cd .. &&
40 git clone . bundle
7be1d62c
JH
41'
42
43test_expect_success "fetch test" '
44 cd "$D" &&
45 echo >file updated by origin &&
46 git commit -a -m "updated by origin" &&
47 cd two &&
48 git fetch &&
49 test -f .git/refs/heads/one &&
50 mine=`git rev-parse refs/heads/one` &&
51 his=`cd ../one && git rev-parse refs/heads/master` &&
52 test "z$mine" = "z$his"
53'
54
6cc7c36d
SB
55test_expect_success "fetch test for-merge" '
56 cd "$D" &&
57 cd three &&
58 git fetch &&
59 test -f .git/refs/heads/two &&
60 test -f .git/refs/heads/one &&
61 master_in_two=`cd ../two && git rev-parse master` &&
62 one_in_two=`cd ../two && git rev-parse one` &&
63 {
64 echo "$master_in_two not-for-merge"
65 echo "$one_in_two "
66 } >expected &&
67 cut -f -2 .git/FETCH_HEAD >actual &&
68 diff expected actual'
69
6c96c0f1
JH
70test_expect_success 'fetch following tags' '
71
72 cd "$D" &&
73 git tag -a -m 'annotated' anno HEAD &&
74 git tag light HEAD &&
75
76 mkdir four &&
77 cd four &&
5c94f87e 78 git init &&
6c96c0f1
JH
79
80 git fetch .. :track &&
81 git show-ref --verify refs/tags/anno &&
82 git show-ref --verify refs/tags/light
83
84'
85
2e0afafe
JS
86test_expect_success 'create bundle 1' '
87 cd "$D" &&
88 echo >file updated again by origin &&
89 git commit -a -m "tip" &&
90 git bundle create bundle1 master^..master
91'
92
8315588b
JS
93test_expect_success 'header of bundle looks right' '
94 head -n 1 "$D"/bundle1 | grep "^#" &&
95 head -n 2 "$D"/bundle1 | grep "^-[0-9a-f]\{40\} " &&
96 head -n 3 "$D"/bundle1 | grep "^[0-9a-f]\{40\} " &&
97 head -n 4 "$D"/bundle1 | grep "^$"
98'
99
2e0afafe
JS
100test_expect_success 'create bundle 2' '
101 cd "$D" &&
102 git bundle create bundle2 master~2..master
103'
104
105test_expect_failure 'unbundle 1' '
106 cd "$D/bundle" &&
107 git checkout -b some-branch &&
108 git fetch "$D/bundle1" master:master
109'
110
8315588b
JS
111test_expect_success 'bundle 1 has only 3 files ' '
112 cd "$D" &&
113 (
114 while read x && test -n "$x"
115 do
116 :;
117 done
118 cat
119 ) <bundle1 >bundle.pack &&
120 git index-pack bundle.pack &&
121 verify=$(git verify-pack -v bundle.pack) &&
122 test 4 = $(echo "$verify" | wc -l)
123'
124
2e0afafe
JS
125test_expect_success 'unbundle 2' '
126 cd "$D/bundle" &&
127 git fetch ../bundle2 master:master &&
128 test "tip" = "$(git log -1 --pretty=oneline master | cut -b42-)"
129'
130
18449ab0
JS
131test_expect_success 'bundle does not prerequisite objects' '
132 cd "$D" &&
133 touch file2 &&
134 git add file2 &&
135 git commit -m add.file2 file2 &&
136 git bundle create bundle3 -1 HEAD &&
6016e35b
SP
137 (
138 while read x && test -n "$x"
139 do
140 :;
141 done
142 cat
143 ) <bundle3 >bundle.pack &&
18449ab0
JS
144 git index-pack bundle.pack &&
145 test 4 = $(git verify-pack -v bundle.pack | wc -l)
146'
147
7fa8254f
JH
148test_expect_success 'bundle should be able to create a full history' '
149
150 cd "$D" &&
151 git tag -a -m '1.0' v1.0 master &&
152 git bundle create bundle4 v1.0
153
154'
155
cd547b48
JS
156test "$TEST_RSYNC" && {
157test_expect_success 'fetch via rsync' '
158 git pack-refs &&
159 mkdir rsynced &&
160 cd rsynced &&
161 git init &&
162 git fetch rsync://127.0.0.1$(pwd)/../.git master:refs/heads/master &&
163 git gc --prune &&
164 test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
165 git fsck --full
166'
167
168test_expect_success 'push via rsync' '
169 mkdir ../rsynced2 &&
170 (cd ../rsynced2 &&
171 git init) &&
172 git push rsync://127.0.0.1$(pwd)/../rsynced2/.git master &&
173 cd ../rsynced2 &&
174 git gc --prune &&
175 test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
176 git fsck --full
177'
178
179test_expect_success 'push via rsync' '
180 cd .. &&
181 mkdir rsynced3 &&
182 (cd rsynced3 &&
183 git init) &&
184 git push --all rsync://127.0.0.1$(pwd)/rsynced3/.git &&
185 cd rsynced3 &&
186 test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
187 git fsck --full
188'
189}
190
7be1d62c 191test_done