]>
Commit | Line | Data |
---|---|---|
7c2c6ee7 SP |
1 | #!/bin/sh |
2 | ||
3 | test_description='git ls-remote' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | test_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 | ||
22 | test_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 | ||
27 | test_expect_success 'ls-remote .git' ' | |
7c2c6ee7 | 28 | git ls-remote .git >actual && |
82ebb0b6 | 29 | test_cmp expected.all actual |
7c2c6ee7 SP |
30 | ' |
31 | ||
32 | test_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 | ||
37 | test_expect_success 'ls-remote self' ' | |
7c2c6ee7 | 38 | git ls-remote self >actual && |
82ebb0b6 | 39 | test_cmp expected.all actual |
7c2c6ee7 SP |
40 | ' |
41 | ||
9c00de5a | 42 | test_expect_success 'dies when no remote specified and no default remotes found' ' |
9c00de5a | 43 | test_must_fail git ls-remote |
9c00de5a TRC |
44 | ' |
45 | ||
46 | test_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 | 57 | test_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 | 62 | test_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 | 87 | test_expect_success 'confuses pattern as remote when no remote specified' ' |
e9d983f1 NTND |
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 | |
348c44e7 JH |
97 | fatal: Could not read from remote repository. |
98 | ||
99 | Please make sure you have the correct access rights | |
100 | and the repository exists. | |
fe6c64ab | 101 | EOF |
9c00de5a | 102 | # |
46284dd1 HV |
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>. | |
9c00de5a TRC |
106 | # We could just as easily have used "master"; the "*" emphasizes its |
107 | # role as a pattern. | |
e9d983f1 | 108 | test_must_fail git ls-remote "$does_not_exist" >actual 2>&1 && |
f2b93b38 | 109 | test_i18ncmp exp actual |
9c00de5a TRC |
110 | ' |
111 | ||
a8724773 | 112 | test_expect_success 'die with non-2 for wrong repository even with --exit-code' ' |
9ddc5ac9 JK |
113 | { |
114 | git ls-remote --exit-code ./no-such-repository | |
115 | status=$? | |
116 | } && | |
a8724773 MS |
117 | test $status != 2 && test $status != 0 |
118 | ' | |
119 | ||
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 | |
124 | ' | |
125 | ||
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 | |
130 | ' | |
131 | ||
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 | |
136 | ' | |
137 | ||
2bc31d16 JK |
138 | test_expect_success 'set up some extra tags for ref hiding' ' |
139 | git tag magic/one && | |
140 | git tag magic/two | |
141 | ' | |
142 | ||
daebaa78 JH |
143 | for configsection in transfer uploadpack |
144 | do | |
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 | |
152 | ' | |
2bc31d16 JK |
153 | |
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 | |
162 | ' | |
163 | ||
daebaa78 JH |
164 | done |
165 | ||
2bc31d16 JK |
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 | |
171 | ' | |
172 | ||
99c08d4e TG |
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 | |
181 | EOF | |
182 | git ls-remote --symref >actual && | |
183 | test_cmp expect actual | |
184 | ' | |
185 | ||
186 | test_expect_success 'ls-remote with filtered symref (refname)' ' | |
187 | cat >expect <<-\EOF && | |
188 | ref: refs/heads/master HEAD | |
189 | 1bd44cb9d13204b0fe1958db0082f5028a16eb3a HEAD | |
190 | EOF | |
191 | git ls-remote --symref . HEAD >actual && | |
192 | test_cmp expect actual | |
193 | ' | |
194 | ||
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 | |
201 | EOF | |
202 | git ls-remote --symref --heads . >actual && | |
203 | test_cmp expect actual | |
204 | ' | |
205 | ||
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 | |
210 | EOF | |
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 | |
215 | ' | |
216 | ||
eb398797 JT |
217 | test_lazy_prereq GIT_DAEMON ' |
218 | test_tristate GIT_TEST_GIT_DAEMON && | |
219 | test "$GIT_TEST_GIT_DAEMON" != false | |
220 | ' | |
221 | ||
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 && | |
230 | { | |
231 | jgit daemon --port="$JGIT_DAEMON_PORT" . >jgit_daemon_output & | |
232 | JGIT_DAEMON_PID=$! | |
233 | } && | |
234 | test_when_finished kill "$JGIT_DAEMON_PID" && | |
235 | { | |
236 | read line && | |
237 | case $line in | |
238 | Exporting*) | |
239 | ;; | |
240 | *) | |
241 | echo "Expected: Exporting" && | |
242 | false;; | |
243 | esac && | |
244 | read line && | |
245 | case $line in | |
246 | "Listening on"*) | |
247 | ;; | |
248 | *) | |
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 | |
256 | ' | |
99c08d4e | 257 | |
4539c218 JK |
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 | |
265 | ' | |
266 | ||
7c2c6ee7 | 267 | test_done |