Skip to content

Commit c8cbf20

Browse files
avargitster
authored andcommitted
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) 399e4a1 ("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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c2c7d17 commit c8cbf20

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

t/t2024-checkout-dwim.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ test_branch_upstream () {
2323
test_cmp expect.upstream actual.upstream
2424
}
2525

26+
status_uno_is_clean () {
27+
>status.expect &&
28+
git status -uno --porcelain >status.actual &&
29+
test_cmp status.expect status.actual
30+
}
31+
2632
test_expect_success 'setup' '
2733
test_commit my_master &&
2834
git init repo_a &&
@@ -55,6 +61,7 @@ test_expect_success 'checkout of non-existing branch fails' '
5561
test_might_fail git branch -D xyzzy &&
5662
5763
test_must_fail git checkout xyzzy &&
64+
status_uno_is_clean &&
5865
test_must_fail git rev-parse --verify refs/heads/xyzzy &&
5966
test_branch master
6067
'
@@ -64,6 +71,7 @@ test_expect_success 'checkout of branch from multiple remotes fails #1' '
6471
test_might_fail git branch -D foo &&
6572
6673
test_must_fail git checkout foo &&
74+
status_uno_is_clean &&
6775
test_must_fail git rev-parse --verify refs/heads/foo &&
6876
test_branch master
6977
'
@@ -73,6 +81,7 @@ test_expect_success 'checkout of branch from a single remote succeeds #1' '
7381
test_might_fail git branch -D bar &&
7482
7583
git checkout bar &&
84+
status_uno_is_clean &&
7685
test_branch bar &&
7786
test_cmp_rev remotes/repo_a/bar HEAD &&
7887
test_branch_upstream bar repo_a bar
@@ -83,13 +92,15 @@ test_expect_success 'checkout of branch from a single remote succeeds #2' '
8392
test_might_fail git branch -D baz &&
8493
8594
git checkout baz &&
95+
status_uno_is_clean &&
8696
test_branch baz &&
8797
test_cmp_rev remotes/other_b/baz HEAD &&
8898
test_branch_upstream baz repo_b baz
8999
'
90100

91101
test_expect_success '--no-guess suppresses branch auto-vivification' '
92102
git checkout -B master &&
103+
status_uno_is_clean &&
93104
test_might_fail git branch -D bar &&
94105
95106
test_must_fail git checkout --no-guess bar &&
@@ -99,6 +110,7 @@ test_expect_success '--no-guess suppresses branch auto-vivification' '
99110

100111
test_expect_success 'setup more remotes with unconventional refspecs' '
101112
git checkout -B master &&
113+
status_uno_is_clean &&
102114
git init repo_c &&
103115
(
104116
cd repo_c &&
@@ -128,70 +140,84 @@ test_expect_success 'setup more remotes with unconventional refspecs' '
128140

129141
test_expect_success 'checkout of branch from multiple remotes fails #2' '
130142
git checkout -B master &&
143+
status_uno_is_clean &&
131144
test_might_fail git branch -D bar &&
132145
133146
test_must_fail git checkout bar &&
147+
status_uno_is_clean &&
134148
test_must_fail git rev-parse --verify refs/heads/bar &&
135149
test_branch master
136150
'
137151

138152
test_expect_success 'checkout of branch from multiple remotes fails #3' '
139153
git checkout -B master &&
154+
status_uno_is_clean &&
140155
test_might_fail git branch -D baz &&
141156
142157
test_must_fail git checkout baz &&
158+
status_uno_is_clean &&
143159
test_must_fail git rev-parse --verify refs/heads/baz &&
144160
test_branch master
145161
'
146162

147163
test_expect_success 'checkout of branch from a single remote succeeds #3' '
148164
git checkout -B master &&
165+
status_uno_is_clean &&
149166
test_might_fail git branch -D spam &&
150167
151168
git checkout spam &&
169+
status_uno_is_clean &&
152170
test_branch spam &&
153171
test_cmp_rev refs/remotes/extra_dir/repo_c/extra_dir/spam HEAD &&
154172
test_branch_upstream spam repo_c spam
155173
'
156174

157175
test_expect_success 'checkout of branch from a single remote succeeds #4' '
158176
git checkout -B master &&
177+
status_uno_is_clean &&
159178
test_might_fail git branch -D eggs &&
160179
161180
git checkout eggs &&
181+
status_uno_is_clean &&
162182
test_branch eggs &&
163183
test_cmp_rev refs/repo_d/eggs HEAD &&
164184
test_branch_upstream eggs repo_d eggs
165185
'
166186

167187
test_expect_success 'checkout of branch with a file having the same name fails' '
168188
git checkout -B master &&
189+
status_uno_is_clean &&
169190
test_might_fail git branch -D spam &&
170191
171192
>spam &&
172193
test_must_fail git checkout spam &&
194+
status_uno_is_clean &&
173195
test_must_fail git rev-parse --verify refs/heads/spam &&
174196
test_branch master
175197
'
176198

177199
test_expect_success 'checkout of branch with a file in subdir having the same name fails' '
178200
git checkout -B master &&
201+
status_uno_is_clean &&
179202
test_might_fail git branch -D spam &&
180203
181204
>spam &&
182205
mkdir sub &&
183206
mv spam sub/spam &&
184207
test_must_fail git -C sub checkout spam &&
208+
status_uno_is_clean &&
185209
test_must_fail git rev-parse --verify refs/heads/spam &&
186210
test_branch master
187211
'
188212

189213
test_expect_success 'checkout <branch> -- succeeds, even if a file with the same name exists' '
190214
git checkout -B master &&
215+
status_uno_is_clean &&
191216
test_might_fail git branch -D spam &&
192217
193218
>spam &&
194219
git checkout spam -- &&
220+
status_uno_is_clean &&
195221
test_branch spam &&
196222
test_cmp_rev refs/remotes/extra_dir/repo_c/extra_dir/spam HEAD &&
197223
test_branch_upstream spam repo_c spam
@@ -200,6 +226,7 @@ test_expect_success 'checkout <branch> -- succeeds, even if a file with the same
200226
test_expect_success 'loosely defined local base branch is reported correctly' '
201227
202228
git checkout master &&
229+
status_uno_is_clean &&
203230
git branch strict &&
204231
git branch loose &&
205232
git commit --allow-empty -m "a bit more" &&
@@ -210,7 +237,9 @@ test_expect_success 'loosely defined local base branch is reported correctly' '
210237
test_config branch.loose.merge master &&
211238
212239
git checkout strict | sed -e "s/strict/BRANCHNAME/g" >expect &&
240+
status_uno_is_clean &&
213241
git checkout loose | sed -e "s/loose/BRANCHNAME/g" >actual &&
242+
status_uno_is_clean &&
214243
215244
test_cmp expect actual
216245
'

0 commit comments

Comments
 (0)