Skip to content

Commit a31e48d

Browse files
newrengitster
authored andcommitted
t7012: add a testcase demonstrating stash apply bugs in sparse checkouts
Applying stashes in sparse-checkouts, particularly when the patterns used to define the sparseness have changed between when the stash was created and when it is applied, has a number of bugs. The primary problem is that stashes are sometimes only partially applied. In most such cases, it does so silently without any warning or error being displayed and with 0 exit status. There are, however, a few cases when non-translated error messages are shown and the stash application aborts early. The first is when there are files present despite the SKIP_WORKTREE bit being set, in which case the error message shown is: error: Entry 'PATHNAME' not uptodate. Cannot merge. The other situation is when a stash contains new files to add to the working tree; in this case, the code aborts early but still has the stash partially applied, and shows the following error message: error: NEWFILE: does not exist and --remove not passed fatal: Unable to process path NEWFILE Add a test that can trigger all three of these problems. Have it carefully check that the working copy and SKIP_WORKTREE bits are as expected after the stash application. The test is currently marked as expected to fail, but subsequent commits will implement the fixes and toggle the expectation. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent faefdd6 commit a31e48d

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

t/t7012-skip-worktree-writing.sh

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,94 @@ test_expect_success '--ignore-skip-worktree-entries leaves worktree alone' '
149149
--diff-filter=D -- keep-me.t
150150
'
151151

152+
test_expect_failure 'stash restore in sparse checkout' '
153+
test_create_repo stash-restore &&
154+
(
155+
cd stash-restore &&
156+
157+
mkdir subdir &&
158+
echo A >subdir/A &&
159+
echo untouched >untouched &&
160+
echo removeme >removeme &&
161+
echo modified >modified &&
162+
git add . &&
163+
git commit -m Initial &&
164+
165+
echo AA >>subdir/A &&
166+
echo addme >addme &&
167+
echo tweaked >>modified &&
168+
rm removeme &&
169+
git add addme &&
170+
171+
git stash push &&
172+
173+
git sparse-checkout set subdir &&
174+
175+
# Ensure after sparse-checkout we only have expected files
176+
cat >expect <<-EOF &&
177+
S modified
178+
S removeme
179+
H subdir/A
180+
S untouched
181+
EOF
182+
git ls-files -t >actual &&
183+
test_cmp expect actual &&
184+
185+
test_path_is_missing addme &&
186+
test_path_is_missing modified &&
187+
test_path_is_missing removeme &&
188+
test_path_is_file subdir/A &&
189+
test_path_is_missing untouched &&
190+
191+
# Put a file in the working directory in the way
192+
echo in the way >modified &&
193+
git stash apply &&
194+
195+
# Ensure stash vivifies modifies paths...
196+
cat >expect <<-EOF &&
197+
H addme
198+
H modified
199+
H removeme
200+
H subdir/A
201+
S untouched
202+
EOF
203+
git ls-files -t >actual &&
204+
test_cmp expect actual &&
205+
206+
# ...and that the paths show up in status as changed...
207+
cat >expect <<-EOF &&
208+
A addme
209+
M modified
210+
D removeme
211+
M subdir/A
212+
?? actual
213+
?? expect
214+
?? modified.stash.XXXXXX
215+
EOF
216+
git status --porcelain | \
217+
sed -e s/stash......./stash.XXXXXX/ >actual &&
218+
test_cmp expect actual &&
219+
220+
# ...and that working directory reflects the files correctly
221+
test_path_is_file addme &&
222+
test_path_is_file modified &&
223+
test_path_is_missing removeme &&
224+
test_path_is_file subdir/A &&
225+
test_path_is_missing untouched &&
226+
227+
# ...including that we have the expected "modified" file...
228+
cat >expect <<-EOF &&
229+
modified
230+
tweaked
231+
EOF
232+
test_cmp expect modified &&
233+
234+
# ...and that the other "modified" file is still present...
235+
echo in the way >expect &&
236+
test_cmp expect modified.stash.*
237+
)
238+
'
239+
152240
#TODO test_expect_failure 'git-apply adds file' false
153241
#TODO test_expect_failure 'git-apply updates file' false
154242
#TODO test_expect_failure 'git-apply removes file' false

0 commit comments

Comments
 (0)