l10n: bg.po: Updated Bulgarian translation (4839t)
[git/debian.git] / t / t5512-ls-remote.sh
blob04b35402c7aab16319713f8aed205e6c9d809893
1 #!/bin/sh
3 test_description='git ls-remote'
5 . ./test-lib.sh
7 test_expect_success setup '
8 >file &&
9 git add file &&
10 test_tick &&
11 git commit -m initial &&
12 git tag mark &&
13 git tag mark1.1 &&
14 git tag mark1.2 &&
15 git tag mark1.10 &&
16 git show-ref --tags -d | sed -e "s/ / /" >expected.tag &&
18 echo "$(git rev-parse HEAD) HEAD" &&
19 git show-ref -d | sed -e "s/ / /"
20 ) >expected.all &&
22 git remote add self "$(pwd)/.git"
25 test_expect_success 'ls-remote --tags .git' '
26 git ls-remote --tags .git >actual &&
27 test_cmp expected.tag actual
30 test_expect_success 'ls-remote .git' '
31 git ls-remote .git >actual &&
32 test_cmp expected.all actual
35 test_expect_success 'ls-remote --tags self' '
36 git ls-remote --tags self >actual &&
37 test_cmp expected.tag actual
40 test_expect_success 'ls-remote self' '
41 git ls-remote self >actual &&
42 test_cmp expected.all actual
45 test_expect_success 'ls-remote --sort="version:refname" --tags self' '
46 cat >expect <<-EOF &&
47 $(git rev-parse mark) refs/tags/mark
48 $(git rev-parse mark1.1) refs/tags/mark1.1
49 $(git rev-parse mark1.2) refs/tags/mark1.2
50 $(git rev-parse mark1.10) refs/tags/mark1.10
51 EOF
52 git ls-remote --sort="version:refname" --tags self >actual &&
53 test_cmp expect actual
56 test_expect_success 'ls-remote --sort="-version:refname" --tags self' '
57 cat >expect <<-EOF &&
58 $(git rev-parse mark1.10) refs/tags/mark1.10
59 $(git rev-parse mark1.2) refs/tags/mark1.2
60 $(git rev-parse mark1.1) refs/tags/mark1.1
61 $(git rev-parse mark) refs/tags/mark
62 EOF
63 git ls-remote --sort="-version:refname" --tags self >actual &&
64 test_cmp expect actual
67 test_expect_success 'ls-remote --sort="-refname" --tags self' '
68 cat >expect <<-EOF &&
69 $(git rev-parse mark1.2) refs/tags/mark1.2
70 $(git rev-parse mark1.10) refs/tags/mark1.10
71 $(git rev-parse mark1.1) refs/tags/mark1.1
72 $(git rev-parse mark) refs/tags/mark
73 EOF
74 git ls-remote --sort="-refname" --tags self >actual &&
75 test_cmp expect actual
78 test_expect_success 'dies when no remote specified and no default remotes found' '
79 test_must_fail git ls-remote
82 test_expect_success 'use "origin" when no remote specified' '
83 URL="$(pwd)/.git" &&
84 echo "From $URL" >exp_err &&
86 git remote add origin "$URL" &&
87 git ls-remote 2>actual_err >actual &&
89 test_cmp exp_err actual_err &&
90 test_cmp expected.all actual
93 test_expect_success 'suppress "From <url>" with -q' '
94 git ls-remote -q 2>actual_err &&
95 test_must_fail test_cmp exp_err actual_err
98 test_expect_success 'use branch.<name>.remote if possible' '
100 # Test that we are indeed using branch.<name>.remote, not "origin", even
101 # though the "origin" remote has been set.
104 # setup a new remote to differentiate from "origin"
105 git clone . other.git &&
107 cd other.git &&
108 echo "$(git rev-parse HEAD) HEAD" &&
109 git show-ref | sed -e "s/ / /"
110 ) >exp &&
112 URL="other.git" &&
113 echo "From $URL" >exp_err &&
115 git remote add other $URL &&
116 git config branch.master.remote other &&
118 git ls-remote 2>actual_err >actual &&
119 test_cmp exp_err actual_err &&
120 test_cmp exp actual
123 test_expect_success 'confuses pattern as remote when no remote specified' '
124 if test_have_prereq MINGW
125 then
126 # Windows does not like asterisks in pathname
127 does_not_exist=master
128 else
129 does_not_exist="refs*master"
130 fi &&
131 cat >exp <<-EOF &&
132 fatal: '\''$does_not_exist'\'' does not appear to be a git repository
133 fatal: Could not read from remote repository.
135 Please make sure you have the correct access rights
136 and the repository exists.
139 # Do not expect "git ls-remote <pattern>" to work; ls-remote needs
140 # <remote> if you want to feed <pattern>, just like you cannot say
141 # fetch <branch>.
142 # We could just as easily have used "master"; the "*" emphasizes its
143 # role as a pattern.
144 test_must_fail git ls-remote "$does_not_exist" >actual 2>&1 &&
145 test_i18ncmp exp actual
148 test_expect_success 'die with non-2 for wrong repository even with --exit-code' '
150 git ls-remote --exit-code ./no-such-repository
151 status=$?
152 } &&
153 test $status != 2 && test $status != 0
156 test_expect_success 'Report success even when nothing matches' '
157 git ls-remote other.git "refs/nsn/*" >actual &&
158 test_must_be_empty actual
161 test_expect_success 'Report no-match with --exit-code' '
162 test_expect_code 2 git ls-remote --exit-code other.git "refs/nsn/*" >actual &&
163 test_must_be_empty actual
166 test_expect_success 'Report match with --exit-code' '
167 git ls-remote --exit-code other.git "refs/tags/*" >actual &&
168 git ls-remote . tags/mark* >expect &&
169 test_cmp expect actual
172 test_expect_success 'set up some extra tags for ref hiding' '
173 git tag magic/one &&
174 git tag magic/two
177 for configsection in transfer uploadpack
179 test_expect_success "Hide some refs with $configsection.hiderefs" '
180 test_config $configsection.hiderefs refs/tags &&
181 git ls-remote . >actual &&
182 test_unconfig $configsection.hiderefs &&
183 git ls-remote . |
184 sed -e "/ refs\/tags\//d" >expect &&
185 test_cmp expect actual
188 test_expect_success "Override hiding of $configsection.hiderefs" '
189 test_when_finished "test_unconfig $configsection.hiderefs" &&
190 git config --add $configsection.hiderefs refs/tags &&
191 git config --add $configsection.hiderefs "!refs/tags/magic" &&
192 git config --add $configsection.hiderefs refs/tags/magic/one &&
193 git ls-remote . >actual &&
194 grep refs/tags/magic/two actual &&
195 ! grep refs/tags/magic/one actual
198 done
200 test_expect_success 'overrides work between mixed transfer/upload-pack hideRefs' '
201 test_config uploadpack.hiderefs refs/tags &&
202 test_config transfer.hiderefs "!refs/tags/magic" &&
203 git ls-remote . >actual &&
204 grep refs/tags/magic actual
207 test_expect_success 'protocol v2 supports hiderefs' '
208 test_config uploadpack.hiderefs refs/tags &&
209 git -c protocol.version=2 ls-remote . >actual &&
210 ! grep refs/tags actual
213 test_expect_success 'ls-remote --symref' '
214 git fetch origin &&
215 cat >expect <<-EOF &&
216 ref: refs/heads/master HEAD
217 $(git rev-parse HEAD) HEAD
218 $(git rev-parse refs/heads/master) refs/heads/master
219 $(git rev-parse HEAD) refs/remotes/origin/HEAD
220 $(git rev-parse refs/remotes/origin/master) refs/remotes/origin/master
221 $(git rev-parse refs/tags/mark) refs/tags/mark
222 $(git rev-parse refs/tags/mark1.1) refs/tags/mark1.1
223 $(git rev-parse refs/tags/mark1.10) refs/tags/mark1.10
224 $(git rev-parse refs/tags/mark1.2) refs/tags/mark1.2
226 # Protocol v2 supports sending symrefs for refs other than HEAD, so use
227 # protocol v0 here.
228 GIT_TEST_PROTOCOL_VERSION=0 git ls-remote --symref >actual &&
229 test_cmp expect actual
232 test_expect_success 'ls-remote with filtered symref (refname)' '
233 rev=$(git rev-parse HEAD) &&
234 cat >expect <<-EOF &&
235 ref: refs/heads/master HEAD
236 $rev HEAD
238 # Protocol v2 supports sending symrefs for refs other than HEAD, so use
239 # protocol v0 here.
240 GIT_TEST_PROTOCOL_VERSION=0 git ls-remote --symref . HEAD >actual &&
241 test_cmp expect actual
244 test_expect_failure 'ls-remote with filtered symref (--heads)' '
245 git symbolic-ref refs/heads/foo refs/tags/mark &&
246 cat >expect <<-EOF &&
247 ref: refs/tags/mark refs/heads/foo
248 $rev refs/heads/foo
249 $rev refs/heads/master
251 # Protocol v2 supports sending symrefs for refs other than HEAD, so use
252 # protocol v0 here.
253 GIT_TEST_PROTOCOL_VERSION=0 git ls-remote --symref --heads . >actual &&
254 test_cmp expect actual
257 test_expect_success 'ls-remote --symref omits filtered-out matches' '
258 cat >expect <<-EOF &&
259 $rev refs/heads/foo
260 $rev refs/heads/master
262 # Protocol v2 supports sending symrefs for refs other than HEAD, so use
263 # protocol v0 here.
264 GIT_TEST_PROTOCOL_VERSION=0 git ls-remote --symref --heads . >actual &&
265 test_cmp expect actual &&
266 GIT_TEST_PROTOCOL_VERSION=0 git ls-remote --symref . "refs/heads/*" >actual &&
267 test_cmp expect actual
270 test_lazy_prereq GIT_DAEMON '
271 test_bool_env GIT_TEST_GIT_DAEMON true
274 # This test spawns a daemon, so run it only if the user would be OK with
275 # testing with git-daemon.
276 test_expect_success PIPE,JGIT,GIT_DAEMON 'indicate no refs in standards-compliant empty remote' '
277 test_set_port JGIT_DAEMON_PORT &&
278 JGIT_DAEMON_PID= &&
279 git init --bare empty.git &&
280 >empty.git/git-daemon-export-ok &&
281 mkfifo jgit_daemon_output &&
283 jgit daemon --port="$JGIT_DAEMON_PORT" . >jgit_daemon_output &
284 JGIT_DAEMON_PID=$!
285 } &&
286 test_when_finished kill "$JGIT_DAEMON_PID" &&
288 read line &&
289 case $line in
290 Exporting*)
293 echo "Expected: Exporting" &&
294 false;;
295 esac &&
296 read line &&
297 case $line in
298 "Listening on"*)
301 echo "Expected: Listening on" &&
302 false;;
303 esac
304 } <jgit_daemon_output &&
305 # --exit-code asks the command to exit with 2 when no
306 # matching refs are found.
307 test_expect_code 2 git ls-remote --exit-code git://localhost:$JGIT_DAEMON_PORT/empty.git
310 test_expect_success 'ls-remote works outside repository' '
311 # It is important for this repo to be inside the nongit
312 # area, as we want a repo name that does not include
313 # slashes (because those inhibit some of our configuration
314 # lookups).
315 nongit git init --bare dst.git &&
316 nongit git ls-remote dst.git
319 test_expect_success 'ls-remote --sort fails gracefully outside repository' '
320 # Use a sort key that requires access to the referenced objects.
321 nongit test_must_fail git ls-remote --sort=authordate "$TRASH_DIRECTORY" 2>err &&
322 test_i18ngrep "^fatal: not a git repository, but the field '\''authordate'\'' requires access to object data" err
325 test_expect_success 'ls-remote patterns work with all protocol versions' '
326 git for-each-ref --format="%(objectname) %(refname)" \
327 refs/heads/master refs/remotes/origin/master >expect &&
328 git -c protocol.version=1 ls-remote . master >actual.v1 &&
329 test_cmp expect actual.v1 &&
330 git -c protocol.version=2 ls-remote . master >actual.v2 &&
331 test_cmp expect actual.v2
334 test_expect_success 'ls-remote prefixes work with all protocol versions' '
335 git for-each-ref --format="%(objectname) %(refname)" \
336 refs/heads/ refs/tags/ >expect &&
337 git -c protocol.version=1 ls-remote --heads --tags . >actual.v1 &&
338 test_cmp expect actual.v1 &&
339 git -c protocol.version=2 ls-remote --heads --tags . >actual.v2 &&
340 test_cmp expect actual.v2
343 test_done