]>
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' ' |
fe6c64ab TG |
88 | cat >exp <<-\EOF && |
89 | fatal: '\''refs*master'\'' does not appear to be a git repository | |
90 | fatal: The remote end hung up unexpectedly | |
91 | EOF | |
9c00de5a TRC |
92 | # |
93 | # Do not expect "git ls-remote <pattern>" to work; ls-remote, correctly, | |
94 | # confuses <pattern> for <remote>. Although ugly, this behaviour is akin | |
95 | # to the confusion of refspecs for remotes by git-fetch and git-push, | |
96 | # eg: | |
97 | # | |
98 | # $ git fetch branch | |
99 | # | |
100 | ||
101 | # We could just as easily have used "master"; the "*" emphasizes its | |
102 | # role as a pattern. | |
103 | test_must_fail git ls-remote refs*master >actual 2>&1 && | |
104 | test_cmp exp actual | |
9c00de5a TRC |
105 | ' |
106 | ||
a8724773 MS |
107 | test_expect_success 'die with non-2 for wrong repository even with --exit-code' ' |
108 | git ls-remote --exit-code ./no-such-repository ;# not && | |
109 | status=$? && | |
110 | test $status != 2 && test $status != 0 | |
111 | ' | |
112 | ||
113 | test_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 | ||
119 | test_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 | ||
125 | test_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 | ||
7c2c6ee7 | 131 | test_done |