@@ -228,4 +228,154 @@ test_expect_success 'stash --invalid-option' '
228
228
test bar,bar2 = $(cat file),$(cat file2)
229
229
'
230
230
231
+ test_expect_success ' stash an added file' '
232
+ git reset --hard &&
233
+ echo new >file3 &&
234
+ git add file3 &&
235
+ git stash save "added file" &&
236
+ ! test -r file3 &&
237
+ git stash apply &&
238
+ test new = "$(cat file3)"
239
+ '
240
+
241
+ test_expect_success ' stash rm then recreate' '
242
+ git reset --hard &&
243
+ git rm file &&
244
+ echo bar7 >file &&
245
+ git stash save "rm then recreate" &&
246
+ test bar = "$(cat file)" &&
247
+ git stash apply &&
248
+ test bar7 = "$(cat file)"
249
+ '
250
+
251
+ test_expect_success ' stash rm and ignore' '
252
+ git reset --hard &&
253
+ git rm file &&
254
+ echo file >.gitignore &&
255
+ git stash save "rm and ignore" &&
256
+ test bar = "$(cat file)" &&
257
+ test file = "$(cat .gitignore)"
258
+ git stash apply &&
259
+ ! test -r file &&
260
+ test file = "$(cat .gitignore)"
261
+ '
262
+
263
+ test_expect_success ' stash rm and ignore (stage .gitignore)' '
264
+ git reset --hard &&
265
+ git rm file &&
266
+ echo file >.gitignore &&
267
+ git add .gitignore &&
268
+ git stash save "rm and ignore (stage .gitignore)" &&
269
+ test bar = "$(cat file)" &&
270
+ ! test -r .gitignore
271
+ git stash apply &&
272
+ ! test -r file &&
273
+ test file = "$(cat .gitignore)"
274
+ '
275
+
276
+ test_expect_success SYMLINKS ' stash file to symlink' '
277
+ git reset --hard &&
278
+ rm file &&
279
+ ln -s file2 file &&
280
+ git stash save "file to symlink" &&
281
+ test -f file &&
282
+ test bar = "$(cat file)" &&
283
+ git stash apply &&
284
+ case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
285
+ '
286
+
287
+ test_expect_success SYMLINKS ' stash file to symlink (stage rm)' '
288
+ git reset --hard &&
289
+ git rm file &&
290
+ ln -s file2 file &&
291
+ git stash save "file to symlink (stage rm)" &&
292
+ test -f file &&
293
+ test bar = "$(cat file)" &&
294
+ git stash apply &&
295
+ case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
296
+ '
297
+
298
+ test_expect_success SYMLINKS ' stash file to symlink (full stage)' '
299
+ git reset --hard &&
300
+ rm file &&
301
+ ln -s file2 file &&
302
+ git add file &&
303
+ git stash save "file to symlink (full stage)" &&
304
+ test -f file &&
305
+ test bar = "$(cat file)" &&
306
+ git stash apply &&
307
+ case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
308
+ '
309
+
310
+ # This test creates a commit with a symlink used for the following tests
311
+
312
+ test_expect_success SYMLINKS ' stash symlink to file' '
313
+ git reset --hard &&
314
+ ln -s file filelink &&
315
+ git add filelink &&
316
+ git commit -m "Add symlink" &&
317
+ rm filelink &&
318
+ cp file filelink &&
319
+ git stash save "symlink to file" &&
320
+ test -h filelink &&
321
+ case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac &&
322
+ git stash apply &&
323
+ ! test -h filelink &&
324
+ test bar = "$(cat file)"
325
+ '
326
+
327
+ test_expect_success SYMLINKS ' stash symlink to file (stage rm)' '
328
+ git reset --hard &&
329
+ git rm filelink &&
330
+ cp file filelink &&
331
+ git stash save "symlink to file (stage rm)" &&
332
+ test -h filelink &&
333
+ case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac &&
334
+ git stash apply &&
335
+ ! test -h filelink &&
336
+ test bar = "$(cat file)"
337
+ '
338
+
339
+ test_expect_success SYMLINKS ' stash symlink to file (full stage)' '
340
+ git reset --hard &&
341
+ rm filelink &&
342
+ cp file filelink &&
343
+ git add filelink &&
344
+ git stash save "symlink to file (full stage)" &&
345
+ test -h filelink &&
346
+ case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac &&
347
+ git stash apply &&
348
+ ! test -h filelink &&
349
+ test bar = "$(cat file)"
350
+ '
351
+
352
+ test_expect_failure ' stash directory to file' '
353
+ git reset --hard &&
354
+ mkdir dir &&
355
+ echo foo >dir/file &&
356
+ git add dir/file &&
357
+ git commit -m "Add file in dir" &&
358
+ rm -fr dir &&
359
+ echo bar >dir &&
360
+ git stash save "directory to file" &&
361
+ test -d dir &&
362
+ test foo = "$(cat dir/file)" &&
363
+ test_must_fail git stash apply &&
364
+ test bar = "$(cat dir)" &&
365
+ git reset --soft HEAD^
366
+ '
367
+
368
+ test_expect_failure ' stash file to directory' '
369
+ git reset --hard &&
370
+ rm file &&
371
+ mkdir file &&
372
+ echo foo >file/file &&
373
+ git stash save "file to directory" &&
374
+ test -f file &&
375
+ test bar = "$(cat file)" &&
376
+ git stash apply &&
377
+ test -f file/file &&
378
+ test foo = "$(cat file/file)"
379
+ '
380
+
231
381
test_done
0 commit comments