@@ -32,9 +32,6 @@ test_expect_success setup '
32
32
'
33
33
34
34
test_incidental_dir_removal () {
35
- works=$1 &&
36
- shift &&
37
-
38
35
test_when_finished " git reset --hard" &&
39
36
40
37
git checkout foo/bar/baz^{commit} &&
@@ -44,88 +41,57 @@ test_incidental_dir_removal () {
44
41
cd foo &&
45
42
" $@ " &&
46
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
57
47
) &&
58
48
test_path_is_missing foo/bar/baz &&
59
49
test_path_is_missing foo/bar &&
60
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
69
52
}
70
53
71
54
test_required_dir_removal () {
72
- works=$1 &&
73
- shift &&
74
-
75
55
git checkout df_conflict^{commit} &&
76
56
test_when_finished " git clean -fdx" &&
77
57
78
58
(
79
59
cd dirORfile &&
80
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
99
72
) &&
100
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
109
75
}
110
76
111
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
113
79
'
114
80
115
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
117
83
'
118
84
119
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
121
87
'
122
88
123
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
125
91
'
126
92
127
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
129
95
'
130
96
131
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'
154
120
GIT_TEST_MERGE_ALGORITHM=ort
155
121
156
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
158
124
'
159
125
160
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
162
128
'
163
129
164
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
166
132
'
167
133
168
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
170
136
'
171
137
172
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
174
140
'
175
141
176
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
178
144
'
179
145
180
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
182
148
'
183
149
184
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
186
152
'
187
153
188
154
test_expect_success ' apply does not remove cwd incidentally' '
189
155
git diff HEAD HEAD~1 >patch &&
190
- test_incidental_dir_removal success git apply ../patch
156
+ test_incidental_dir_removal git apply ../patch
191
157
'
192
158
193
159
test_incidental_untracked_dir_removal () {
194
- works=$1 &&
195
- shift &&
196
-
197
160
test_when_finished " git reset --hard" &&
198
161
199
162
git checkout foo/bar/baz^{commit} &&
@@ -205,38 +168,24 @@ test_incidental_untracked_dir_removal () {
205
168
cd untracked &&
206
169
" $@ " &&
207
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
218
174
) &&
219
175
test_path_is_missing empty &&
220
176
test_path_is_missing untracked/random &&
221
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
230
179
}
231
180
232
181
test_expect_success ' clean does not remove cwd incidentally' '
233
- test_incidental_untracked_dir_removal success \
182
+ test_incidental_untracked_dir_removal \
234
183
git -C .. clean -fd -e warnings . >warnings &&
235
184
grep "Refusing to remove current working directory" warnings
236
185
'
237
186
238
187
test_expect_success ' stash does not remove cwd incidentally' '
239
- test_incidental_untracked_dir_removal success \
188
+ test_incidental_untracked_dir_removal \
240
189
git stash --include-untracked
241
190
'
242
191
0 commit comments