]>
Commit | Line | Data |
---|---|---|
28fb8438 JS |
1 | #!/bin/sh |
2 | ||
3 | test_description='test <branch>@{upstream} syntax' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | ||
8 | test_expect_success 'setup' ' | |
9 | ||
10 | test_commit 1 && | |
11 | git checkout -b side && | |
12 | test_commit 2 && | |
13 | git checkout master && | |
14 | git clone . clone && | |
15 | test_commit 3 && | |
16 | (cd clone && | |
17 | test_commit 4 && | |
1b4aee94 ZJS |
18 | git branch --track my-side origin/side && |
19 | git branch --track local-master master && | |
20 | git remote add -t master master-only .. && | |
21 | git fetch master-only && | |
22 | git branch bad-upstream && | |
23 | git config branch.bad-upstream.remote master-only && | |
24 | git config branch.bad-upstream.merge refs/heads/side | |
25 | ) | |
28fb8438 JS |
26 | ' |
27 | ||
1b4aee94 ZJS |
28 | sq="'" |
29 | ||
28fb8438 JS |
30 | full_name () { |
31 | (cd clone && | |
32 | git rev-parse --symbolic-full-name "$@") | |
33 | } | |
34 | ||
35 | commit_subject () { | |
36 | (cd clone && | |
37 | git show -s --pretty=format:%s "$@") | |
38 | } | |
39 | ||
1b4aee94 ZJS |
40 | error_message () { |
41 | (cd clone && | |
42 | test_must_fail git rev-parse --verify "$@") | |
43 | } | |
44 | ||
28fb8438 JS |
45 | test_expect_success '@{upstream} resolves to correct full name' ' |
46 | test refs/remotes/origin/master = "$(full_name @{upstream})" | |
47 | ' | |
48 | ||
49 | test_expect_success '@{u} resolves to correct full name' ' | |
50 | test refs/remotes/origin/master = "$(full_name @{u})" | |
51 | ' | |
52 | ||
53 | test_expect_success 'my-side@{upstream} resolves to correct full name' ' | |
54 | test refs/remotes/origin/side = "$(full_name my-side@{u})" | |
55 | ' | |
56 | ||
57 | test_expect_success 'my-side@{u} resolves to correct commit' ' | |
58 | git checkout side && | |
59 | test_commit 5 && | |
60 | (cd clone && git fetch) && | |
61 | test 2 = "$(commit_subject my-side)" && | |
62 | test 5 = "$(commit_subject my-side@{u})" | |
63 | ' | |
64 | ||
65 | test_expect_success 'not-tracking@{u} fails' ' | |
66 | test_must_fail full_name non-tracking@{u} && | |
67 | (cd clone && git checkout --no-track -b non-tracking) && | |
68 | test_must_fail full_name non-tracking@{u} | |
69 | ' | |
70 | ||
71 | test_expect_success '<branch>@{u}@{1} resolves correctly' ' | |
72 | test_commit 6 && | |
73 | (cd clone && git fetch) && | |
74 | test 5 = $(commit_subject my-side@{u}@{1}) | |
75 | ' | |
76 | ||
77 | test_expect_success '@{u} without specifying branch fails on a detached HEAD' ' | |
78 | git checkout HEAD^0 && | |
79 | test_must_fail git rev-parse @{u} | |
80 | ' | |
81 | ||
69add8e6 JH |
82 | test_expect_success 'checkout -b new my-side@{u} forks from the same' ' |
83 | ( | |
84 | cd clone && | |
85 | git checkout -b new my-side@{u} && | |
86 | git rev-parse --symbolic-full-name my-side@{u} >expect && | |
87 | git rev-parse --symbolic-full-name new@{u} >actual && | |
88 | test_cmp expect actual | |
89 | ) | |
90 | ' | |
91 | ||
ae0ba8e2 | 92 | test_expect_success 'merge my-side@{u} records the correct name' ' |
69add8e6 | 93 | ( |
69add8e6 JH |
94 | cd clone || exit |
95 | git checkout master || exit | |
96 | git branch -D new ;# can fail but is ok | |
97 | git branch -t new my-side@{u} && | |
98 | git merge -s ours new@{u} && | |
99 | git show -s --pretty=format:%s >actual && | |
13931236 | 100 | echo "Merge remote-tracking branch ${sq}origin/side${sq}" >expect && |
69add8e6 JH |
101 | test_cmp expect actual |
102 | ) | |
103 | ' | |
104 | ||
ae0ba8e2 | 105 | test_expect_success 'branch -d other@{u}' ' |
69add8e6 JH |
106 | git checkout -t -b other master && |
107 | git branch -d @{u} && | |
108 | git for-each-ref refs/heads/master >actual && | |
109 | >expect && | |
110 | test_cmp expect actual | |
111 | ' | |
112 | ||
ae0ba8e2 | 113 | test_expect_success 'checkout other@{u}' ' |
69add8e6 JH |
114 | git branch -f master HEAD && |
115 | git checkout -t -b another master && | |
116 | git checkout @{u} && | |
117 | git symbolic-ref HEAD >actual && | |
118 | echo refs/heads/master >expect && | |
119 | test_cmp expect actual | |
120 | ' | |
121 | ||
1b4aee94 ZJS |
122 | test_expect_success 'branch@{u} works when tracking a local branch' ' |
123 | test refs/heads/master = "$(full_name local-master@{u})" | |
124 | ' | |
125 | ||
126 | test_expect_success 'branch@{u} error message when no upstream' ' | |
127 | cat >expect <<-EOF && | |
17c82211 | 128 | error: No upstream configured for branch ${sq}non-tracking${sq} |
1b4aee94 ZJS |
129 | fatal: Needed a single revision |
130 | EOF | |
131 | error_message non-tracking@{u} 2>actual && | |
64720288 | 132 | test_i18ncmp expect actual |
1b4aee94 ZJS |
133 | ' |
134 | ||
135 | test_expect_success '@{u} error message when no upstream' ' | |
136 | cat >expect <<-EOF && | |
17c82211 | 137 | error: No upstream configured for branch ${sq}master${sq} |
1b4aee94 ZJS |
138 | fatal: Needed a single revision |
139 | EOF | |
140 | test_must_fail git rev-parse --verify @{u} 2>actual && | |
64720288 | 141 | test_i18ncmp expect actual |
1b4aee94 ZJS |
142 | ' |
143 | ||
144 | test_expect_success 'branch@{u} error message with misspelt branch' ' | |
145 | cat >expect <<-EOF && | |
bb0dab5d | 146 | error: No such branch: ${sq}no-such-branch${sq} |
1b4aee94 ZJS |
147 | fatal: Needed a single revision |
148 | EOF | |
149 | error_message no-such-branch@{u} 2>actual && | |
64720288 | 150 | test_i18ncmp expect actual |
1b4aee94 ZJS |
151 | ' |
152 | ||
153 | test_expect_success '@{u} error message when not on a branch' ' | |
154 | cat >expect <<-EOF && | |
9884e67f | 155 | error: HEAD does not point to a branch |
1b4aee94 ZJS |
156 | fatal: Needed a single revision |
157 | EOF | |
158 | git checkout HEAD^0 && | |
159 | test_must_fail git rev-parse --verify @{u} 2>actual && | |
64720288 | 160 | test_i18ncmp expect actual |
1b4aee94 ZJS |
161 | ' |
162 | ||
163 | test_expect_success 'branch@{u} error message if upstream branch not fetched' ' | |
164 | cat >expect <<-EOF && | |
17c82211 | 165 | error: Upstream branch ${sq}refs/heads/side${sq} not stored as a remote-tracking branch |
1b4aee94 ZJS |
166 | fatal: Needed a single revision |
167 | EOF | |
168 | error_message bad-upstream@{u} 2>actual && | |
64720288 | 169 | test_i18ncmp expect actual |
1b4aee94 ZJS |
170 | ' |
171 | ||
172 | test_expect_success 'pull works when tracking a local branch' ' | |
173 | ( | |
174 | cd clone && | |
175 | git checkout local-master && | |
176 | git pull | |
177 | ) | |
178 | ' | |
179 | ||
180 | # makes sense if the previous one succeeded | |
181 | test_expect_success '@{u} works when tracking a local branch' ' | |
182 | test refs/heads/master = "$(full_name @{u})" | |
183 | ' | |
184 | ||
105e4733 JH |
185 | cat >expect <<EOF |
186 | commit 8f489d01d0cc65c3b0f09504ec50b5ed02a70bd5 | |
187 | Reflog: master@{0} (C O Mitter <committer@example.com>) | |
188 | Reflog message: branch: Created from HEAD | |
189 | Author: A U Thor <author@example.com> | |
190 | Date: Thu Apr 7 15:15:13 2005 -0700 | |
191 | ||
192 | 3 | |
193 | EOF | |
194 | test_expect_success 'log -g other@{u}' ' | |
195 | git log -1 -g other@{u} >actual && | |
196 | test_cmp expect actual | |
197 | ' | |
198 | ||
199 | cat >expect <<EOF | |
200 | commit 8f489d01d0cc65c3b0f09504ec50b5ed02a70bd5 | |
201 | Reflog: master@{Thu Apr 7 15:17:13 2005 -0700} (C O Mitter <committer@example.com>) | |
202 | Reflog message: branch: Created from HEAD | |
203 | Author: A U Thor <author@example.com> | |
204 | Date: Thu Apr 7 15:15:13 2005 -0700 | |
205 | ||
206 | 3 | |
207 | EOF | |
208 | ||
209 | test_expect_success 'log -g other@{u}@{now}' ' | |
210 | git log -1 -g other@{u}@{now} >actual && | |
211 | test_cmp expect actual | |
212 | ' | |
213 | ||
28fb8438 | 214 | test_done |