Skip to content

Commit 1b4aee9

Browse files
keszybzgitster
authored andcommitted
t1507: add tests to document @{upstream} behaviour
In preparation for future changes, add tests which show error messages with @{upstream} in various conditions: - test branch@{u} with . as remote - check error message for branch@{u} on a branch with * no upstream, * on a branch with a configured upstream which doesn't have a remote-tracking branch - check error message for branch@{u} when branch 'branch' does not exist - check error message for @{u} without the branch name Right now the messages are very similar, but various cases can and will be distinguished. Note: test_i18ncmp is not used, because currently error output is not internationalized. test_cmp will be switched to test_i18ncmp in a later patch, when error messages are internationalized. Signed-off-by: Zbigniew Jędrzejewski-Szmek <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e8dde3e commit 1b4aee9

File tree

1 file changed

+78
-3
lines changed

1 file changed

+78
-3
lines changed

t/t1507-rev-parse-upstream.sh

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,18 @@ test_expect_success 'setup' '
1515
test_commit 3 &&
1616
(cd clone &&
1717
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+
)
2026
'
2127

28+
sq="'"
29+
2230
full_name () {
2331
(cd clone &&
2432
git rev-parse --symbolic-full-name "$@")
@@ -29,6 +37,11 @@ commit_subject () {
2937
git show -s --pretty=format:%s "$@")
3038
}
3139

40+
error_message () {
41+
(cd clone &&
42+
test_must_fail git rev-parse --verify "$@")
43+
}
44+
3245
test_expect_success '@{upstream} resolves to correct full name' '
3346
test refs/remotes/origin/master = "$(full_name @{upstream})"
3447
'
@@ -78,7 +91,6 @@ test_expect_success 'checkout -b new my-side@{u} forks from the same' '
7891

7992
test_expect_success 'merge my-side@{u} records the correct name' '
8093
(
81-
sq="'\''" &&
8294
cd clone || exit
8395
git checkout master || exit
8496
git branch -D new ;# can fail but is ok
@@ -107,6 +119,69 @@ test_expect_success 'checkout other@{u}' '
107119
test_cmp expect actual
108120
'
109121

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+
110185
cat >expect <<EOF
111186
commit 8f489d01d0cc65c3b0f09504ec50b5ed02a70bd5
112187
Reflog: master@{0} (C O Mitter <[email protected]>)

0 commit comments

Comments
 (0)