]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5512-ls-remote.sh
wrapper.c: add and use warn_on_fopen_errors()
[thirdparty/git.git] / t / t5512-ls-remote.sh
CommitLineData
7c2c6ee7
SP
1#!/bin/sh
2
3test_description='git ls-remote'
4
5. ./test-lib.sh
6
7test_expect_success setup '
7c2c6ee7
SP
8 >file &&
9 git add file &&
10 test_tick &&
11 git commit -m initial &&
12 git tag mark &&
13 git show-ref --tags -d | sed -e "s/ / /" >expected.tag &&
14 (
15 echo "$(git rev-parse HEAD) HEAD"
16 git show-ref -d | sed -e "s/ / /"
17 ) >expected.all &&
18
f69e836f 19 git remote add self "$(pwd)/.git"
7c2c6ee7
SP
20'
21
22test_expect_success 'ls-remote --tags .git' '
7c2c6ee7 23 git ls-remote --tags .git >actual &&
82ebb0b6 24 test_cmp expected.tag actual
7c2c6ee7
SP
25'
26
27test_expect_success 'ls-remote .git' '
7c2c6ee7 28 git ls-remote .git >actual &&
82ebb0b6 29 test_cmp expected.all actual
7c2c6ee7
SP
30'
31
32test_expect_success 'ls-remote --tags self' '
7c2c6ee7 33 git ls-remote --tags self >actual &&
82ebb0b6 34 test_cmp expected.tag actual
7c2c6ee7
SP
35'
36
37test_expect_success 'ls-remote self' '
7c2c6ee7 38 git ls-remote self >actual &&
82ebb0b6 39 test_cmp expected.all actual
7c2c6ee7
SP
40'
41
9c00de5a 42test_expect_success 'dies when no remote specified and no default remotes found' '
9c00de5a 43 test_must_fail git ls-remote
9c00de5a
TRC
44'
45
46test_expect_success 'use "origin" when no remote specified' '
cefb2a5e
TRC
47 URL="$(pwd)/.git" &&
48 echo "From $URL" >exp_err &&
49
50 git remote add origin "$URL" &&
51 git ls-remote 2>actual_err >actual &&
52
53 test_cmp exp_err actual_err &&
9c00de5a 54 test_cmp expected.all actual
9c00de5a
TRC
55'
56
cefb2a5e 57test_expect_success 'suppress "From <url>" with -q' '
cefb2a5e
TRC
58 git ls-remote -q 2>actual_err &&
59 test_must_fail test_cmp exp_err actual_err
cefb2a5e
TRC
60'
61
9c00de5a 62test_expect_success 'use branch.<name>.remote if possible' '
9c00de5a
TRC
63 #
64 # Test that we are indeed using branch.<name>.remote, not "origin", even
65 # though the "origin" remote has been set.
66 #
67
68 # setup a new remote to differentiate from "origin"
69 git clone . other.git &&
70 (
71 cd other.git &&
72 echo "$(git rev-parse HEAD) HEAD"
73 git show-ref | sed -e "s/ / /"
74 ) >exp &&
75
cefb2a5e
TRC
76 URL="other.git" &&
77 echo "From $URL" >exp_err &&
78
79 git remote add other $URL &&
9c00de5a
TRC
80 git config branch.master.remote other &&
81
cefb2a5e
TRC
82 git ls-remote 2>actual_err >actual &&
83 test_cmp exp_err actual_err &&
9c00de5a 84 test_cmp exp actual
9c00de5a
TRC
85'
86
9c00de5a 87test_expect_success 'confuses pattern as remote when no remote specified' '
fe6c64ab
TG
88 cat >exp <<-\EOF &&
89 fatal: '\''refs*master'\'' does not appear to be a git repository
348c44e7
JH
90 fatal: Could not read from remote repository.
91
92 Please make sure you have the correct access rights
93 and the repository exists.
fe6c64ab 94 EOF
9c00de5a 95 #
46284dd1
HV
96 # Do not expect "git ls-remote <pattern>" to work; ls-remote needs
97 # <remote> if you want to feed <pattern>, just like you cannot say
98 # fetch <branch>.
9c00de5a
TRC
99 # We could just as easily have used "master"; the "*" emphasizes its
100 # role as a pattern.
101 test_must_fail git ls-remote refs*master >actual 2>&1 &&
f2b93b38 102 test_i18ncmp exp actual
9c00de5a
TRC
103'
104
a8724773 105test_expect_success 'die with non-2 for wrong repository even with --exit-code' '
9ddc5ac9
JK
106 {
107 git ls-remote --exit-code ./no-such-repository
108 status=$?
109 } &&
a8724773
MS
110 test $status != 2 && test $status != 0
111'
112
113test_expect_success 'Report success even when nothing matches' '
114 git ls-remote other.git "refs/nsn/*" >actual &&
115 >expect &&
116 test_cmp expect actual
117'
118
119test_expect_success 'Report no-match with --exit-code' '
120 test_expect_code 2 git ls-remote --exit-code other.git "refs/nsn/*" >actual &&
121 >expect &&
122 test_cmp expect actual
123'
124
125test_expect_success 'Report match with --exit-code' '
126 git ls-remote --exit-code other.git "refs/tags/*" >actual &&
127 git ls-remote . tags/mark >expect &&
128 test_cmp expect actual
129'
130
2bc31d16
JK
131test_expect_success 'set up some extra tags for ref hiding' '
132 git tag magic/one &&
133 git tag magic/two
134'
135
daebaa78
JH
136for configsection in transfer uploadpack
137do
138 test_expect_success "Hide some refs with $configsection.hiderefs" '
139 test_config $configsection.hiderefs refs/tags &&
140 git ls-remote . >actual &&
141 test_unconfig $configsection.hiderefs &&
142 git ls-remote . |
143 sed -e "/ refs\/tags\//d" >expect &&
144 test_cmp expect actual
145 '
2bc31d16
JK
146
147 test_expect_success "Override hiding of $configsection.hiderefs" '
148 test_when_finished "test_unconfig $configsection.hiderefs" &&
149 git config --add $configsection.hiderefs refs/tags &&
150 git config --add $configsection.hiderefs "!refs/tags/magic" &&
151 git config --add $configsection.hiderefs refs/tags/magic/one &&
152 git ls-remote . >actual &&
153 grep refs/tags/magic/two actual &&
154 ! grep refs/tags/magic/one actual
155 '
156
daebaa78
JH
157done
158
2bc31d16
JK
159test_expect_success 'overrides work between mixed transfer/upload-pack hideRefs' '
160 test_config uploadpack.hiderefs refs/tags &&
161 test_config transfer.hiderefs "!refs/tags/magic" &&
162 git ls-remote . >actual &&
163 grep refs/tags/magic actual
164'
165
99c08d4e
TG
166test_expect_success 'ls-remote --symref' '
167 cat >expect <<-\EOF &&
168 ref: refs/heads/master HEAD
169 1bd44cb9d13204b0fe1958db0082f5028a16eb3a HEAD
170 1bd44cb9d13204b0fe1958db0082f5028a16eb3a refs/heads/master
171 1bd44cb9d13204b0fe1958db0082f5028a16eb3a refs/remotes/origin/HEAD
172 1bd44cb9d13204b0fe1958db0082f5028a16eb3a refs/remotes/origin/master
173 1bd44cb9d13204b0fe1958db0082f5028a16eb3a refs/tags/mark
174 EOF
175 git ls-remote --symref >actual &&
176 test_cmp expect actual
177'
178
179test_expect_success 'ls-remote with filtered symref (refname)' '
180 cat >expect <<-\EOF &&
181 ref: refs/heads/master HEAD
182 1bd44cb9d13204b0fe1958db0082f5028a16eb3a HEAD
183 EOF
184 git ls-remote --symref . HEAD >actual &&
185 test_cmp expect actual
186'
187
188test_expect_failure 'ls-remote with filtered symref (--heads)' '
189 git symbolic-ref refs/heads/foo refs/tags/mark &&
190 cat >expect <<-\EOF &&
191 ref: refs/tags/mark refs/heads/foo
192 1bd44cb9d13204b0fe1958db0082f5028a16eb3a refs/heads/foo
193 1bd44cb9d13204b0fe1958db0082f5028a16eb3a refs/heads/master
194 EOF
195 git ls-remote --symref --heads . >actual &&
196 test_cmp expect actual
197'
198
199test_expect_success 'ls-remote --symref omits filtered-out matches' '
200 cat >expect <<-\EOF &&
201 1bd44cb9d13204b0fe1958db0082f5028a16eb3a refs/heads/foo
202 1bd44cb9d13204b0fe1958db0082f5028a16eb3a refs/heads/master
203 EOF
204 git ls-remote --symref --heads . >actual &&
205 test_cmp expect actual &&
206 git ls-remote --symref . "refs/heads/*" >actual &&
207 test_cmp expect actual
208'
209
eb398797
JT
210test_lazy_prereq GIT_DAEMON '
211 test_tristate GIT_TEST_GIT_DAEMON &&
212 test "$GIT_TEST_GIT_DAEMON" != false
213'
214
215# This test spawns a daemon, so run it only if the user would be OK with
216# testing with git-daemon.
217test_expect_success PIPE,JGIT,GIT_DAEMON 'indicate no refs in standards-compliant empty remote' '
218 JGIT_DAEMON_PORT=${JGIT_DAEMON_PORT-${this_test#t}} &&
219 JGIT_DAEMON_PID= &&
220 git init --bare empty.git &&
221 >empty.git/git-daemon-export-ok &&
222 mkfifo jgit_daemon_output &&
223 {
224 jgit daemon --port="$JGIT_DAEMON_PORT" . >jgit_daemon_output &
225 JGIT_DAEMON_PID=$!
226 } &&
227 test_when_finished kill "$JGIT_DAEMON_PID" &&
228 {
229 read line &&
230 case $line in
231 Exporting*)
232 ;;
233 *)
234 echo "Expected: Exporting" &&
235 false;;
236 esac &&
237 read line &&
238 case $line in
239 "Listening on"*)
240 ;;
241 *)
242 echo "Expected: Listening on" &&
243 false;;
244 esac
245 } <jgit_daemon_output &&
246 # --exit-code asks the command to exit with 2 when no
247 # matching refs are found.
248 test_expect_code 2 git ls-remote --exit-code git://localhost:$JGIT_DAEMON_PORT/empty.git
249'
99c08d4e 250
4539c218
JK
251test_expect_success 'ls-remote works outside repository' '
252 # It is important for this repo to be inside the nongit
253 # area, as we want a repo name that does not include
254 # slashes (because those inhibit some of our configuration
255 # lookups).
256 nongit git init --bare dst.git &&
257 nongit git ls-remote dst.git
258'
259
7c2c6ee7 260test_done