15
test_commit 3 &&
16
(cd clone &&
17
test_commit 4 &&
18
- git branch --track my-side origin/side)
19
-
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
+ )
26
'
27
28
+sq="'"
29
+
30
full_name () {
31
(cd clone &&
32
git rev-parse --symbolic-full-name "$@")
37
git show -s --pretty=format:%s "$@")
38
}
39
40
+error_message () {
41
+ (cd clone &&
42
+ test_must_fail git rev-parse --verify "$@")
43
+}
44
+
45
test_expect_success '@{upstream} resolves to correct full name' '
46
test refs/remotes/origin/master = "$(full_name @{upstream})"
47
'
91
92
test_expect_success 'merge my-side@{u} records the correct name' '
93
(
81
- sq="'\''" &&
94
cd clone || exit
95
git checkout master || exit
96
git branch -D new ;# can fail but is ok
119
test_cmp expect actual
120
'
121
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 &&
128
+ error: No upstream branch found for ${sq}non-tracking${sq}
129
+ fatal: Needed a single revision
130
+ EOF
131
+ error_message non-tracking@{u} 2>actual &&
132
+ test_cmp expect actual
133
+'
134
+
135
+test_expect_success '@{u} error message when no upstream' '
136
+ cat >expect <<-EOF &&
137
+ error: No upstream branch found for ${sq}${sq}
138
+ fatal: Needed a single revision
139
+ EOF
140
+ test_must_fail git rev-parse --verify @{u} 2>actual &&
141
+ test_cmp expect actual
142
+'
143
+
144
+test_expect_success 'branch@{u} error message with misspelt branch' '
145
+ cat >expect <<-EOF &&
146
+ error: No upstream branch found for ${sq}no-such-branch${sq}
147
+ fatal: Needed a single revision
148
+ EOF
149
+ error_message no-such-branch@{u} 2>actual &&
150
+ test_cmp expect actual
151
+'
152
+
153
+test_expect_success '@{u} error message when not on a branch' '
154
+ cat >expect <<-EOF &&
155
+ error: No upstream branch found for ${sq}${sq}
156
+ fatal: Needed a single revision
157
+ EOF
158
+ git checkout HEAD^0 &&
159
+ test_must_fail git rev-parse --verify @{u} 2>actual &&
160
+ test_cmp expect actual
161
+'
162
+
163
+test_expect_success 'branch@{u} error message if upstream branch not fetched' '
164
+ cat >expect <<-EOF &&
165
+ error: No upstream branch found for ${sq}bad-upstream${sq}
166
+ fatal: Needed a single revision
167
+ EOF
168
+ error_message bad-upstream@{u} 2>actual &&
169
+ test_cmp expect actual
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
+
185
cat >expect <<EOF
186
commit 8f489d01d0cc65c3b0f09504ec50b5ed02a70bd5
187
Reflog: master@{0} (C O Mitter <committer@example.com>)