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 ' | |
8 | ||
9 | >file && | |
10 | git add file && | |
11 | test_tick && | |
12 | git commit -m initial && | |
13 | git tag mark && | |
14 | git show-ref --tags -d | sed -e "s/ / /" >expected.tag && | |
15 | ( | |
16 | echo "$(git rev-parse HEAD) HEAD" | |
17 | git show-ref -d | sed -e "s/ / /" | |
18 | ) >expected.all && | |
19 | ||
f69e836f | 20 | git remote add self "$(pwd)/.git" |
7c2c6ee7 SP |
21 | |
22 | ' | |
23 | ||
24 | test_expect_success 'ls-remote --tags .git' ' | |
25 | ||
26 | git ls-remote --tags .git >actual && | |
82ebb0b6 | 27 | test_cmp expected.tag actual |
7c2c6ee7 SP |
28 | |
29 | ' | |
30 | ||
31 | test_expect_success 'ls-remote .git' ' | |
32 | ||
33 | git ls-remote .git >actual && | |
82ebb0b6 | 34 | test_cmp expected.all actual |
7c2c6ee7 SP |
35 | |
36 | ' | |
37 | ||
38 | test_expect_success 'ls-remote --tags self' ' | |
39 | ||
40 | git ls-remote --tags self >actual && | |
82ebb0b6 | 41 | test_cmp expected.tag actual |
7c2c6ee7 SP |
42 | |
43 | ' | |
44 | ||
45 | test_expect_success 'ls-remote self' ' | |
46 | ||
47 | git ls-remote self >actual && | |
82ebb0b6 | 48 | test_cmp expected.all actual |
7c2c6ee7 SP |
49 | |
50 | ' | |
51 | ||
9c00de5a TRC |
52 | test_expect_success 'dies when no remote specified and no default remotes found' ' |
53 | ||
54 | test_must_fail git ls-remote | |
55 | ||
56 | ' | |
57 | ||
58 | test_expect_success 'use "origin" when no remote specified' ' | |
59 | ||
cefb2a5e TRC |
60 | URL="$(pwd)/.git" && |
61 | echo "From $URL" >exp_err && | |
62 | ||
63 | git remote add origin "$URL" && | |
64 | git ls-remote 2>actual_err >actual && | |
65 | ||
66 | test_cmp exp_err actual_err && | |
9c00de5a TRC |
67 | test_cmp expected.all actual |
68 | ||
69 | ' | |
70 | ||
cefb2a5e TRC |
71 | test_expect_success 'suppress "From <url>" with -q' ' |
72 | ||
73 | git ls-remote -q 2>actual_err && | |
74 | test_must_fail test_cmp exp_err actual_err | |
75 | ||
76 | ' | |
77 | ||
9c00de5a TRC |
78 | test_expect_success 'use branch.<name>.remote if possible' ' |
79 | ||
80 | # | |
81 | # Test that we are indeed using branch.<name>.remote, not "origin", even | |
82 | # though the "origin" remote has been set. | |
83 | # | |
84 | ||
85 | # setup a new remote to differentiate from "origin" | |
86 | git clone . other.git && | |
87 | ( | |
88 | cd other.git && | |
89 | echo "$(git rev-parse HEAD) HEAD" | |
90 | git show-ref | sed -e "s/ / /" | |
91 | ) >exp && | |
92 | ||
cefb2a5e TRC |
93 | URL="other.git" && |
94 | echo "From $URL" >exp_err && | |
95 | ||
96 | git remote add other $URL && | |
9c00de5a TRC |
97 | git config branch.master.remote other && |
98 | ||
cefb2a5e TRC |
99 | git ls-remote 2>actual_err >actual && |
100 | test_cmp exp_err actual_err && | |
9c00de5a TRC |
101 | test_cmp exp actual |
102 | ||
103 | ' | |
104 | ||
105 | cat >exp <<EOF | |
106 | fatal: 'refs*master' does not appear to be a git repository | |
107 | fatal: The remote end hung up unexpectedly | |
108 | EOF | |
109 | test_expect_success 'confuses pattern as remote when no remote specified' ' | |
110 | # | |
111 | # Do not expect "git ls-remote <pattern>" to work; ls-remote, correctly, | |
112 | # confuses <pattern> for <remote>. Although ugly, this behaviour is akin | |
113 | # to the confusion of refspecs for remotes by git-fetch and git-push, | |
114 | # eg: | |
115 | # | |
116 | # $ git fetch branch | |
117 | # | |
118 | ||
119 | # We could just as easily have used "master"; the "*" emphasizes its | |
120 | # role as a pattern. | |
121 | test_must_fail git ls-remote refs*master >actual 2>&1 && | |
122 | test_cmp exp actual | |
123 | ||
124 | ' | |
125 | ||
7c2c6ee7 | 126 | test_done |