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 <zbyszek@in.waw.pl> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Zbigniew Jędrzejewski-Szmek committed Apr 14, 2012 at 09:54 UTC 1b4aee94aaffd5e6fdf3020434b3fa6f0c5cfb2b
1 file changed +78 -3
t/t1507-rev-parse-upstream.sh
+78 -3
@@ -15,10 +15,18 @@ test_expect_success 'setup' '
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 "$@")
@@ -29,6 +37,11 @@ commit_subject () {
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 '
@@ -78,7 +91,6 @@ test_expect_success 'checkout -b new my-side@{u} forks from the same' '
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
@@ -107,6 +119,69 @@ test_expect_success 'checkout other@{u}' '
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>)