t2501: simplify the tests since we can now assume desired behavior
We no longer are dealing with a mixture of previous and desired behavior, so simplify the tests a bit. Acked-by: Derrick Stolee <stolee@gmail.com> Acked-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Dec 9, 2021 at 05:08 UTC
324b170b88475811cb0506a30b4710ffc89ae936
1 file changed
+36
-87
t/t2501-cwd-empty.sh
+36
-87
@@ -32,9 +32,6 @@ test_expect_success setup '
32
'
33
34
test_incidental_dir_removal () {
35
- works=$1 &&
36
- shift &&
37
-
35
test_when_finished "git reset --hard" &&
36
37
git checkout foo/bar/baz^{commit} &&
@@ -44,88 +41,57 @@ test_incidental_dir_removal () {
41
cd foo &&
42
"$@" &&
43
47
- # Although we want pwd & git status to pass, test for existing
48
- # rather than desired behavior.
49
- if test "$works" = "success"
50
- then
51
- test-tool getcwd &&
52
- git status --porcelain
53
- else
54
- ! test-tool getcwd &&
55
- test_might_fail git status --porcelain
56
- fi
44
+ # Make sure foo still exists, and commands needing it work
45
+ test-tool getcwd &&
46
+ git status --porcelain
47
) &&
48
test_path_is_missing foo/bar/baz &&
49
test_path_is_missing foo/bar &&
50
61
- # Although we want dir to be present, test for existing rather
62
- # than desired behavior.
63
- if test "$works" = "success"
64
- then
65
- test_path_is_dir foo
66
- else
67
- test_path_is_missing foo
68
- fi
51
+ test_path_is_dir foo
52
}
53
54
test_required_dir_removal () {
72
- works=$1 &&
73
- shift &&
74
-
55
git checkout df_conflict^{commit} &&
56
test_when_finished "git clean -fdx" &&
57
58
(
59
cd dirORfile &&
60
81
- # We'd like for the command to fail (much as it would if there
82
- # was an untracked file there), and for the index and worktree
83
- # to be left clean with pwd and git status working afterwards.
84
- # But test for existing rather than desired behavior.
85
- if test "$works" = "success"
86
- then
87
- test_must_fail "$@" 2>../error &&
88
- grep "Refusing to remove.*current working directory" ../error &&
89
-
90
- git diff --exit-code HEAD &&
91
-
92
- test-tool getcwd &&
93
- git status --porcelain
94
- else
95
- "$@" &&
96
- ! test-tool getcwd &&
97
- test_might_fail git status --porcelain
98
- fi
61
+ # Ensure command refuses to run
62
+ test_must_fail "$@" 2>../error &&
63
+ grep "Refusing to remove.*current working directory" ../error &&
64
+
65
+ # ...and that the index and working tree are left clean
66
+ git diff --exit-code HEAD &&
67
+
68
+ # Ensure that getcwd and git status do not error out (which
69
+ # they might if the current working directory had been removed)
70
+ test-tool getcwd &&
71
+ git status --porcelain
72
) &&
73
101
- # Although we want dirORfile to be present, test for existing rather
102
- # than desired behavior.
103
- if test "$works" = "success"
104
- then
105
- test_path_is_dir dirORfile
106
- else
107
- test_path_is_file dirORfile
108
- fi
74
+ test_path_is_dir dirORfile
75
}
76
77
test_expect_success 'checkout does not clean cwd incidentally' '
112
- test_incidental_dir_removal success git checkout init
78
+ test_incidental_dir_removal git checkout init
79
'
80
81
test_expect_success 'checkout fails if cwd needs to be removed' '
116
- test_required_dir_removal success git checkout fd_conflict
82
+ test_required_dir_removal git checkout fd_conflict
83
'
84
85
test_expect_success 'reset --hard does not clean cwd incidentally' '
120
- test_incidental_dir_removal success git reset --hard init
86
+ test_incidental_dir_removal git reset --hard init
87
'
88
89
test_expect_success 'reset --hard fails if cwd needs to be removed' '
124
- test_required_dir_removal success git reset --hard fd_conflict
90
+ test_required_dir_removal git reset --hard fd_conflict
91
'
92
93
test_expect_success 'merge does not clean cwd incidentally' '
128
- test_incidental_dir_removal success git merge reverted
94
+ test_incidental_dir_removal git merge reverted
95
'
96
97
# This file uses some simple merges where
@@ -154,46 +120,43 @@ test_expect_success 'merge fails if cwd needs to be removed; recursive friendly'
120
GIT_TEST_MERGE_ALGORITHM=ort
121
122
test_expect_success 'merge fails if cwd needs to be removed' '
157
- test_required_dir_removal success git merge fd_conflict
123
+ test_required_dir_removal git merge fd_conflict
124
'
125
126
test_expect_success 'cherry-pick does not clean cwd incidentally' '
161
- test_incidental_dir_removal success git cherry-pick reverted
127
+ test_incidental_dir_removal git cherry-pick reverted
128
'
129
130
test_expect_success 'cherry-pick fails if cwd needs to be removed' '
165
- test_required_dir_removal success git cherry-pick fd_conflict
131
+ test_required_dir_removal git cherry-pick fd_conflict
132
'
133
134
test_expect_success 'rebase does not clean cwd incidentally' '
169
- test_incidental_dir_removal success git rebase reverted
135
+ test_incidental_dir_removal git rebase reverted
136
'
137
138
test_expect_success 'rebase fails if cwd needs to be removed' '
173
- test_required_dir_removal success git rebase fd_conflict
139
+ test_required_dir_removal git rebase fd_conflict
140
'
141
142
test_expect_success 'revert does not clean cwd incidentally' '
177
- test_incidental_dir_removal success git revert HEAD
143
+ test_incidental_dir_removal git revert HEAD
144
'
145
146
test_expect_success 'revert fails if cwd needs to be removed' '
181
- test_required_dir_removal success git revert undo_fd_conflict
147
+ test_required_dir_removal git revert undo_fd_conflict
148
'
149
150
test_expect_success 'rm does not clean cwd incidentally' '
185
- test_incidental_dir_removal success git rm bar/baz.t
151
+ test_incidental_dir_removal git rm bar/baz.t
152
'
153
154
test_expect_success 'apply does not remove cwd incidentally' '
155
git diff HEAD HEAD~1 >patch &&
190
- test_incidental_dir_removal success git apply ../patch
156
+ test_incidental_dir_removal git apply ../patch
157
'
158
159
test_incidental_untracked_dir_removal () {
194
- works=$1 &&
195
- shift &&
196
-
160
test_when_finished "git reset --hard" &&
161
162
git checkout foo/bar/baz^{commit} &&
@@ -205,38 +168,24 @@ test_incidental_untracked_dir_removal () {
168
cd untracked &&
169
"$@" &&
170
208
- # Although we want pwd & git status to pass, test for existing
209
- # rather than desired behavior.
210
- if test "$works" = "success"
211
- then
212
- test-tool getcwd &&
213
- git status --porcelain
214
- else
215
- ! test-tool getcwd &&
216
- test_might_fail git status --porcelain
217
- fi
171
+ # Make sure untracked still exists, and commands needing it work
172
+ test-tool getcwd &&
173
+ git status --porcelain
174
) &&
175
test_path_is_missing empty &&
176
test_path_is_missing untracked/random &&
177
222
- # Although we want dir to be present, test for existing rather
223
- # than desired behavior.
224
- if test "$works" = "success"
225
- then
226
- test_path_is_dir untracked
227
- else
228
- test_path_is_missing untracked
229
- fi
178
+ test_path_is_dir untracked
179
}
180
181
test_expect_success 'clean does not remove cwd incidentally' '
233
- test_incidental_untracked_dir_removal success \
182
+ test_incidental_untracked_dir_removal \
183
git -C .. clean -fd -e warnings . >warnings &&
184
grep "Refusing to remove current working directory" warnings
185
'
186
187
test_expect_success 'stash does not remove cwd incidentally' '
239
- test_incidental_untracked_dir_removal success \
188
+ test_incidental_untracked_dir_removal \
189
git stash --include-untracked
190
'
191