read_packed_refs(): make parsing of the header line more robust
[git.git] / t / t5512-ls-remote.sh
blob02106c9226605f3b241160a8b46e6dbf3a9d3fc0
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 show-ref --tags -d | sed -e "s/ / /" >expected.tag &&
15 echo "$(git rev-parse HEAD) HEAD"
16 git show-ref -d | sed -e "s/ / /"
17 ) >expected.all &&
19 git remote add self "$(pwd)/.git"
22 test_expect_success 'ls-remote --tags .git' '
23 git ls-remote --tags .git >actual &&
24 test_cmp expected.tag actual
27 test_expect_success 'ls-remote .git' '
28 git ls-remote .git >actual &&
29 test_cmp expected.all actual
32 test_expect_success 'ls-remote --tags self' '
33 git ls-remote --tags self >actual &&
34 test_cmp expected.tag actual
37 test_expect_success 'ls-remote self' '
38 git ls-remote self >actual &&
39 test_cmp expected.all actual
42 test_expect_success 'dies when no remote specified and no default remotes found' '
43 test_must_fail git ls-remote
46 test_expect_success 'use "origin" when no remote specified' '
47 URL="$(pwd)/.git" &&
48 echo "From $URL" >exp_err &&
50 git remote add origin "$URL" &&
51 git ls-remote 2>actual_err >actual &&
53 test_cmp exp_err actual_err &&
54 test_cmp expected.all actual
57 test_expect_success 'suppress "From <url>" with -q' '
58 git ls-remote -q 2>actual_err &&
59 test_must_fail test_cmp exp_err actual_err
62 test_expect_success 'use branch.<name>.remote if possible' '
64 # Test that we are indeed using branch.<name>.remote, not "origin", even
65 # though the "origin" remote has been set.
68 # setup a new remote to differentiate from "origin"
69 git clone . other.git &&
71 cd other.git &&
72 echo "$(git rev-parse HEAD) HEAD"
73 git show-ref | sed -e "s/ / /"
74 ) >exp &&
76 URL="other.git" &&
77 echo "From $URL" >exp_err &&
79 git remote add other $URL &&
80 git config branch.master.remote other &&
82 git ls-remote 2>actual_err >actual &&
83 test_cmp exp_err actual_err &&
84 test_cmp exp actual
87 test_expect_success 'confuses pattern as remote when no remote specified' '
88 if test_have_prereq MINGW
89 then
90 # Windows does not like asterisks in pathname
91 does_not_exist=master
92 else
93 does_not_exist="refs*master"
94 fi &&
95 cat >exp <<-EOF &&
96 fatal: '\''$does_not_exist'\'' does not appear to be a git repository
97 fatal: Could not read from remote repository.
99 Please make sure you have the correct access rights
100 and the repository exists.
103 # Do not expect "git ls-remote <pattern>" to work; ls-remote needs
104 # <remote> if you want to feed <pattern>, just like you cannot say
105 # fetch <branch>.
106 # We could just as easily have used "master"; the "*" emphasizes its
107 # role as a pattern.
108 test_must_fail git ls-remote "$does_not_exist" >actual 2>&1 &&
109 test_i18ncmp exp actual
112 test_expect_success 'die with non-2 for wrong repository even with --exit-code' '
114 git ls-remote --exit-code ./no-such-repository
115 status=$?
116 } &&
117 test $status != 2 && test $status != 0
120 test_expect_success 'Report success even when nothing matches' '
121 git ls-remote other.git "refs/nsn/*" >actual &&
122 >expect &&
123 test_cmp expect actual
126 test_expect_success 'Report no-match with --exit-code' '
127 test_expect_code 2 git ls-remote --exit-code other.git "refs/nsn/*" >actual &&
128 >expect &&
129 test_cmp expect actual
132 test_expect_success 'Report match with --exit-code' '
133 git ls-remote --exit-code other.git "refs/tags/*" >actual &&
134 git ls-remote . tags/mark >expect &&
135 test_cmp expect actual
138 test_expect_success 'set up some extra tags for ref hiding' '
139 git tag magic/one &&
140 git tag magic/two
143 for configsection in transfer uploadpack
145 test_expect_success "Hide some refs with $configsection.hiderefs" '
146 test_config $configsection.hiderefs refs/tags &&
147 git ls-remote . >actual &&
148 test_unconfig $configsection.hiderefs &&
149 git ls-remote . |
150 sed -e "/ refs\/tags\//d" >expect &&
151 test_cmp expect actual
154 test_expect_success "Override hiding of $configsection.hiderefs" '
155 test_when_finished "test_unconfig $configsection.hiderefs" &&
156 git config --add $configsection.hiderefs refs/tags &&
157 git config --add $configsection.hiderefs "!refs/tags/magic" &&
158 git config --add $configsection.hiderefs refs/tags/magic/one &&
159 git ls-remote . >actual &&
160 grep refs/tags/magic/two actual &&
161 ! grep refs/tags/magic/one actual
164 done
166 test_expect_success 'overrides work between mixed transfer/upload-pack hideRefs' '
167 test_config uploadpack.hiderefs refs/tags &&
168 test_config transfer.hiderefs "!refs/tags/magic" &&
169 git ls-remote . >actual &&
170 grep refs/tags/magic actual
173 test_expect_success 'ls-remote --symref' '
174 cat >expect <<-\EOF &&
175 ref: refs/heads/master HEAD
176 1bd44cb9d13204b0fe1958db0082f5028a16eb3a HEAD
177 1bd44cb9d13204b0fe1958db0082f5028a16eb3a refs/heads/master
178 1bd44cb9d13204b0fe1958db0082f5028a16eb3a refs/remotes/origin/HEAD
179 1bd44cb9d13204b0fe1958db0082f5028a16eb3a refs/remotes/origin/master
180 1bd44cb9d13204b0fe1958db0082f5028a16eb3a refs/tags/mark
182 git ls-remote --symref >actual &&
183 test_cmp expect actual
186 test_expect_success 'ls-remote with filtered symref (refname)' '
187 cat >expect <<-\EOF &&
188 ref: refs/heads/master HEAD
189 1bd44cb9d13204b0fe1958db0082f5028a16eb3a HEAD
191 git ls-remote --symref . HEAD >actual &&
192 test_cmp expect actual
195 test_expect_failure 'ls-remote with filtered symref (--heads)' '
196 git symbolic-ref refs/heads/foo refs/tags/mark &&
197 cat >expect <<-\EOF &&
198 ref: refs/tags/mark refs/heads/foo
199 1bd44cb9d13204b0fe1958db0082f5028a16eb3a refs/heads/foo
200 1bd44cb9d13204b0fe1958db0082f5028a16eb3a refs/heads/master
202 git ls-remote --symref --heads . >actual &&
203 test_cmp expect actual
206 test_expect_success 'ls-remote --symref omits filtered-out matches' '
207 cat >expect <<-\EOF &&
208 1bd44cb9d13204b0fe1958db0082f5028a16eb3a refs/heads/foo
209 1bd44cb9d13204b0fe1958db0082f5028a16eb3a refs/heads/master
211 git ls-remote --symref --heads . >actual &&
212 test_cmp expect actual &&
213 git ls-remote --symref . "refs/heads/*" >actual &&
214 test_cmp expect actual
217 test_lazy_prereq GIT_DAEMON '
218 test_tristate GIT_TEST_GIT_DAEMON &&
219 test "$GIT_TEST_GIT_DAEMON" != false
222 # This test spawns a daemon, so run it only if the user would be OK with
223 # testing with git-daemon.
224 test_expect_success PIPE,JGIT,GIT_DAEMON 'indicate no refs in standards-compliant empty remote' '
225 JGIT_DAEMON_PORT=${JGIT_DAEMON_PORT-${this_test#t}} &&
226 JGIT_DAEMON_PID= &&
227 git init --bare empty.git &&
228 >empty.git/git-daemon-export-ok &&
229 mkfifo jgit_daemon_output &&
231 jgit daemon --port="$JGIT_DAEMON_PORT" . >jgit_daemon_output &
232 JGIT_DAEMON_PID=$!
233 } &&
234 test_when_finished kill "$JGIT_DAEMON_PID" &&
236 read line &&
237 case $line in
238 Exporting*)
241 echo "Expected: Exporting" &&
242 false;;
243 esac &&
244 read line &&
245 case $line in
246 "Listening on"*)
249 echo "Expected: Listening on" &&
250 false;;
251 esac
252 } <jgit_daemon_output &&
253 # --exit-code asks the command to exit with 2 when no
254 # matching refs are found.
255 test_expect_code 2 git ls-remote --exit-code git://localhost:$JGIT_DAEMON_PORT/empty.git
258 test_expect_success 'ls-remote works outside repository' '
259 # It is important for this repo to be inside the nongit
260 # area, as we want a repo name that does not include
261 # slashes (because those inhibit some of our configuration
262 # lookups).
263 nongit git init --bare dst.git &&
264 nongit git ls-remote dst.git
267 test_done