checkout tests: index should be clean after dwim checkout

Assert that whenever there's a DWIM checkout that the index should be clean afterwards, in addition to the correct branch being checked-out. The way the DWIM checkout code in checkout.[ch] works is by looping over all remotes, and for each remote trying to find if a given reference name only exists on that remote, or if it exists anywhere else. This is done by starting out with a `unique = 1` tracking variable in a struct shared by the entire loop, which will get set to `0` if the data reference is not unique. Thus if we find a match we know the dst_oid member of tracking_name_data must be correct, since it's associated with the only reference on the only remote that could have matched our query. But if there was ever a mismatch there for some reason we might end up with the correct branch checked out, but at the wrong oid, which would show whatever the difference between the two staged in the index (checkout branch A, stage changes from the state of branch B). So let's amend the tests (mostly added in) 399e4a1c56 ("t2024: Add tests verifying current DWIM behavior of 'git checkout <branch>'", 2013-04-21) to always assert that "status" is clean after we run "checkout", that's being done with "-uno" because there's going to be some untracked files related to the test itself which we don't care about. In all these tests (DWIM or otherwise) we start with a clean index, so these tests are asserting that that's still the case after the "checkout", failed or otherwise. Then if we ever run into this sort of regression, either in the existing code or with a new feature, we'll know. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Jun 5, 2018 at 14:40 UTC c8cbf20cc2a54e07705f14ddef901d676b5410ea
1 file changed +29
t/t2024-checkout-dwim.sh
+29
@@ -23,6 +23,12 @@ test_branch_upstream () {
23 test_cmp expect.upstream actual.upstream
24 }
25
26 +status_uno_is_clean () {
27 + >status.expect &&
28 + git status -uno --porcelain >status.actual &&
29 + test_cmp status.expect status.actual
30 +}
31 +
32 test_expect_success 'setup' '
33 test_commit my_master &&
34 git init repo_a &&
@@ -55,6 +61,7 @@ test_expect_success 'checkout of non-existing branch fails' '
61 test_might_fail git branch -D xyzzy &&
62
63 test_must_fail git checkout xyzzy &&
64 + status_uno_is_clean &&
65 test_must_fail git rev-parse --verify refs/heads/xyzzy &&
66 test_branch master
67 '
@@ -64,6 +71,7 @@ test_expect_success 'checkout of branch from multiple remotes fails #1' '
71 test_might_fail git branch -D foo &&
72
73 test_must_fail git checkout foo &&
74 + status_uno_is_clean &&
75 test_must_fail git rev-parse --verify refs/heads/foo &&
76 test_branch master
77 '
@@ -73,6 +81,7 @@ test_expect_success 'checkout of branch from a single remote succeeds #1' '
81 test_might_fail git branch -D bar &&
82
83 git checkout bar &&
84 + status_uno_is_clean &&
85 test_branch bar &&
86 test_cmp_rev remotes/repo_a/bar HEAD &&
87 test_branch_upstream bar repo_a bar
@@ -83,6 +92,7 @@ test_expect_success 'checkout of branch from a single remote succeeds #2' '
92 test_might_fail git branch -D baz &&
93
94 git checkout baz &&
95 + status_uno_is_clean &&
96 test_branch baz &&
97 test_cmp_rev remotes/other_b/baz HEAD &&
98 test_branch_upstream baz repo_b baz
@@ -90,6 +100,7 @@ test_expect_success 'checkout of branch from a single remote succeeds #2' '
100
101 test_expect_success '--no-guess suppresses branch auto-vivification' '
102 git checkout -B master &&
103 + status_uno_is_clean &&
104 test_might_fail git branch -D bar &&
105
106 test_must_fail git checkout --no-guess bar &&
@@ -99,6 +110,7 @@ test_expect_success '--no-guess suppresses branch auto-vivification' '
110
111 test_expect_success 'setup more remotes with unconventional refspecs' '
112 git checkout -B master &&
113 + status_uno_is_clean &&
114 git init repo_c &&
115 (
116 cd repo_c &&
@@ -128,27 +140,33 @@ test_expect_success 'setup more remotes with unconventional refspecs' '
140
141 test_expect_success 'checkout of branch from multiple remotes fails #2' '
142 git checkout -B master &&
143 + status_uno_is_clean &&
144 test_might_fail git branch -D bar &&
145
146 test_must_fail git checkout bar &&
147 + status_uno_is_clean &&
148 test_must_fail git rev-parse --verify refs/heads/bar &&
149 test_branch master
150 '
151
152 test_expect_success 'checkout of branch from multiple remotes fails #3' '
153 git checkout -B master &&
154 + status_uno_is_clean &&
155 test_might_fail git branch -D baz &&
156
157 test_must_fail git checkout baz &&
158 + status_uno_is_clean &&
159 test_must_fail git rev-parse --verify refs/heads/baz &&
160 test_branch master
161 '
162
163 test_expect_success 'checkout of branch from a single remote succeeds #3' '
164 git checkout -B master &&
165 + status_uno_is_clean &&
166 test_might_fail git branch -D spam &&
167
168 git checkout spam &&
169 + status_uno_is_clean &&
170 test_branch spam &&
171 test_cmp_rev refs/remotes/extra_dir/repo_c/extra_dir/spam HEAD &&
172 test_branch_upstream spam repo_c spam
@@ -156,9 +174,11 @@ test_expect_success 'checkout of branch from a single remote succeeds #3' '
174
175 test_expect_success 'checkout of branch from a single remote succeeds #4' '
176 git checkout -B master &&
177 + status_uno_is_clean &&
178 test_might_fail git branch -D eggs &&
179
180 git checkout eggs &&
181 + status_uno_is_clean &&
182 test_branch eggs &&
183 test_cmp_rev refs/repo_d/eggs HEAD &&
184 test_branch_upstream eggs repo_d eggs
@@ -166,32 +186,38 @@ test_expect_success 'checkout of branch from a single remote succeeds #4' '
186
187 test_expect_success 'checkout of branch with a file having the same name fails' '
188 git checkout -B master &&
189 + status_uno_is_clean &&
190 test_might_fail git branch -D spam &&
191
192 >spam &&
193 test_must_fail git checkout spam &&
194 + status_uno_is_clean &&
195 test_must_fail git rev-parse --verify refs/heads/spam &&
196 test_branch master
197 '
198
199 test_expect_success 'checkout of branch with a file in subdir having the same name fails' '
200 git checkout -B master &&
201 + status_uno_is_clean &&
202 test_might_fail git branch -D spam &&
203
204 >spam &&
205 mkdir sub &&
206 mv spam sub/spam &&
207 test_must_fail git -C sub checkout spam &&
208 + status_uno_is_clean &&
209 test_must_fail git rev-parse --verify refs/heads/spam &&
210 test_branch master
211 '
212
213 test_expect_success 'checkout <branch> -- succeeds, even if a file with the same name exists' '
214 git checkout -B master &&
215 + status_uno_is_clean &&
216 test_might_fail git branch -D spam &&
217
218 >spam &&
219 git checkout spam -- &&
220 + status_uno_is_clean &&
221 test_branch spam &&
222 test_cmp_rev refs/remotes/extra_dir/repo_c/extra_dir/spam HEAD &&
223 test_branch_upstream spam repo_c spam
@@ -200,6 +226,7 @@ test_expect_success 'checkout <branch> -- succeeds, even if a file with the same
226 test_expect_success 'loosely defined local base branch is reported correctly' '
227
228 git checkout master &&
229 + status_uno_is_clean &&
230 git branch strict &&
231 git branch loose &&
232 git commit --allow-empty -m "a bit more" &&
@@ -210,7 +237,9 @@ test_expect_success 'loosely defined local base branch is reported correctly' '
237 test_config branch.loose.merge master &&
238
239 git checkout strict | sed -e "s/strict/BRANCHNAME/g" >expect &&
240 + status_uno_is_clean &&
241 git checkout loose | sed -e "s/loose/BRANCHNAME/g" >actual &&
242 + status_uno_is_clean &&
243
244 test_cmp expect actual
245 '