]>
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 | ||
617cf931 KK |
57 | test_expect_success 'refs/heads/my-side@{upstream} does not resolve to my-side{upstream}' ' |
58 | test_must_fail full_name refs/heads/my-side@{upstream} | |
59 | ' | |
60 | ||
28fb8438 JS |
61 | test_expect_success 'my-side@{u} resolves to correct commit' ' |
62 | git checkout side && | |
63 | test_commit 5 && | |
64 | (cd clone && git fetch) && | |
65 | test 2 = "$(commit_subject my-side)" && | |
66 | test 5 = "$(commit_subject my-side@{u})" | |
67 | ' | |
68 | ||
69 | test_expect_success 'not-tracking@{u} fails' ' | |
70 | test_must_fail full_name non-tracking@{u} && | |
71 | (cd clone && git checkout --no-track -b non-tracking) && | |
72 | test_must_fail full_name non-tracking@{u} | |
73 | ' | |
74 | ||
75 | test_expect_success '<branch>@{u}@{1} resolves correctly' ' | |
76 | test_commit 6 && | |
77 | (cd clone && git fetch) && | |
78 | test 5 = $(commit_subject my-side@{u}@{1}) | |
79 | ' | |
80 | ||
81 | test_expect_success '@{u} without specifying branch fails on a detached HEAD' ' | |
82 | git checkout HEAD^0 && | |
83 | test_must_fail git rev-parse @{u} | |
84 | ' | |
85 | ||
69add8e6 JH |
86 | test_expect_success 'checkout -b new my-side@{u} forks from the same' ' |
87 | ( | |
88 | cd clone && | |
89 | git checkout -b new my-side@{u} && | |
90 | git rev-parse --symbolic-full-name my-side@{u} >expect && | |
91 | git rev-parse --symbolic-full-name new@{u} >actual && | |
92 | test_cmp expect actual | |
93 | ) | |
94 | ' | |
95 | ||
ae0ba8e2 | 96 | test_expect_success 'merge my-side@{u} records the correct name' ' |
69add8e6 | 97 | ( |
69add8e6 JH |
98 | cd clone || exit |
99 | git checkout master || exit | |
100 | git branch -D new ;# can fail but is ok | |
101 | git branch -t new my-side@{u} && | |
102 | git merge -s ours new@{u} && | |
103 | git show -s --pretty=format:%s >actual && | |
13931236 | 104 | echo "Merge remote-tracking branch ${sq}origin/side${sq}" >expect && |
69add8e6 JH |
105 | test_cmp expect actual |
106 | ) | |
107 | ' | |
108 | ||
ae0ba8e2 | 109 | test_expect_success 'branch -d other@{u}' ' |
69add8e6 JH |
110 | git checkout -t -b other master && |
111 | git branch -d @{u} && | |
112 | git for-each-ref refs/heads/master >actual && | |
113 | >expect && | |
114 | test_cmp expect actual | |
115 | ' | |
116 | ||
ae0ba8e2 | 117 | test_expect_success 'checkout other@{u}' ' |
69add8e6 JH |
118 | git branch -f master HEAD && |
119 | git checkout -t -b another master && | |
120 | git checkout @{u} && | |
121 | git symbolic-ref HEAD >actual && | |
122 | echo refs/heads/master >expect && | |
123 | test_cmp expect actual | |
124 | ' | |
125 | ||
1b4aee94 ZJS |
126 | test_expect_success 'branch@{u} works when tracking a local branch' ' |
127 | test refs/heads/master = "$(full_name local-master@{u})" | |
128 | ' | |
129 | ||
130 | test_expect_success 'branch@{u} error message when no upstream' ' | |
131 | cat >expect <<-EOF && | |
17bf4ff3 | 132 | fatal: No upstream configured for branch ${sq}non-tracking${sq} |
1b4aee94 ZJS |
133 | EOF |
134 | error_message non-tracking@{u} 2>actual && | |
64720288 | 135 | test_i18ncmp expect actual |
1b4aee94 ZJS |
136 | ' |
137 | ||
138 | test_expect_success '@{u} error message when no upstream' ' | |
139 | cat >expect <<-EOF && | |
17bf4ff3 | 140 | fatal: No upstream configured for branch ${sq}master${sq} |
1b4aee94 ZJS |
141 | EOF |
142 | test_must_fail git rev-parse --verify @{u} 2>actual && | |
64720288 | 143 | test_i18ncmp expect actual |
1b4aee94 ZJS |
144 | ' |
145 | ||
146 | test_expect_success 'branch@{u} error message with misspelt branch' ' | |
147 | cat >expect <<-EOF && | |
17bf4ff3 | 148 | fatal: No such branch: ${sq}no-such-branch${sq} |
1b4aee94 ZJS |
149 | EOF |
150 | error_message no-such-branch@{u} 2>actual && | |
64720288 | 151 | test_i18ncmp expect actual |
1b4aee94 ZJS |
152 | ' |
153 | ||
154 | test_expect_success '@{u} error message when not on a branch' ' | |
155 | cat >expect <<-EOF && | |
17bf4ff3 | 156 | fatal: HEAD does not point to a branch |
1b4aee94 ZJS |
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 && | |
17bf4ff3 | 165 | fatal: Upstream branch ${sq}refs/heads/side${sq} not stored as a remote-tracking branch |
1b4aee94 ZJS |
166 | EOF |
167 | error_message bad-upstream@{u} 2>actual && | |
64720288 | 168 | test_i18ncmp expect actual |
1b4aee94 ZJS |
169 | ' |
170 | ||
171 | test_expect_success 'pull works when tracking a local branch' ' | |
172 | ( | |
173 | cd clone && | |
174 | git checkout local-master && | |
175 | git pull | |
176 | ) | |
177 | ' | |
178 | ||
179 | # makes sense if the previous one succeeded | |
180 | test_expect_success '@{u} works when tracking a local branch' ' | |
181 | test refs/heads/master = "$(full_name @{u})" | |
182 | ' | |
183 | ||
105e4733 JH |
184 | cat >expect <<EOF |
185 | commit 8f489d01d0cc65c3b0f09504ec50b5ed02a70bd5 | |
186 | Reflog: master@{0} (C O Mitter <committer@example.com>) | |
187 | Reflog message: branch: Created from HEAD | |
188 | Author: A U Thor <author@example.com> | |
189 | Date: Thu Apr 7 15:15:13 2005 -0700 | |
190 | ||
191 | 3 | |
192 | EOF | |
193 | test_expect_success 'log -g other@{u}' ' | |
194 | git log -1 -g other@{u} >actual && | |
195 | test_cmp expect actual | |
196 | ' | |
197 | ||
198 | cat >expect <<EOF | |
199 | commit 8f489d01d0cc65c3b0f09504ec50b5ed02a70bd5 | |
200 | Reflog: master@{Thu Apr 7 15:17:13 2005 -0700} (C O Mitter <committer@example.com>) | |
201 | Reflog message: branch: Created from HEAD | |
202 | Author: A U Thor <author@example.com> | |
203 | Date: Thu Apr 7 15:15:13 2005 -0700 | |
204 | ||
205 | 3 | |
206 | EOF | |
207 | ||
208 | test_expect_success 'log -g other@{u}@{now}' ' | |
209 | git log -1 -g other@{u}@{now} >actual && | |
210 | test_cmp expect actual | |
211 | ' | |
212 | ||
3f6eb30f JK |
213 | test_expect_success '@{reflog}-parsing does not look beyond colon' ' |
214 | echo content >@{yesterday} && | |
215 | git add @{yesterday} && | |
216 | git commit -m "funny reflog file" && | |
217 | git hash-object @{yesterday} >expect && | |
218 | git rev-parse HEAD:@{yesterday} >actual | |
219 | ' | |
220 | ||
221 | test_expect_success '@{upstream}-parsing does not look beyond colon' ' | |
222 | echo content >@{upstream} && | |
223 | git add @{upstream} && | |
224 | git commit -m "funny upstream file" && | |
225 | git hash-object @{upstream} >expect && | |
226 | git rev-parse HEAD:@{upstream} >actual | |
227 | ' | |
228 | ||
28fb8438 | 229 | test_done |