t3903-stash.sh 18.3 KB
Newer Older
1 2 3 4 5
#!/bin/sh
#
# Copyright (c) 2007 Johannes E Schindelin
#

6
test_description='Test git stash'
7 8 9 10 11 12

. ./test-lib.sh

test_expect_success 'stash some dirty working directory' '
	echo 1 > file &&
	git add file &&
13 14
	echo unrelated >other-file &&
	git add other-file &&
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
	test_tick &&
	git commit -m initial &&
	echo 2 > file &&
	git add file &&
	echo 3 > file &&
	test_tick &&
	git stash &&
	git diff-files --quiet &&
	git diff-index --cached --quiet HEAD
'

cat > expect << EOF
diff --git a/file b/file
index 0cfbf08..00750ed 100644
--- a/file
+++ b/file
@@ -1 +1 @@
-2
+3
EOF

test_expect_success 'parents of stash' '
	test $(git rev-parse stash^) = $(git rev-parse HEAD) &&
	git diff stash^2..stash > output &&
39
	test_cmp output expect
40 41
'

42 43 44 45 46 47
test_expect_success 'applying bogus stash does nothing' '
	test_must_fail git stash apply stash@{1} &&
	echo 1 >expect &&
	test_cmp expect file
'

48 49 50 51 52 53 54 55 56 57 58 59 60
test_expect_success 'apply does not need clean working directory' '
	echo 4 >other-file &&
	git stash apply &&
	echo 3 >expect &&
	test_cmp expect file
'

test_expect_success 'apply does not clobber working directory changes' '
	git reset --hard &&
	echo 4 >file &&
	test_must_fail git stash apply &&
	echo 4 >expect &&
	test_cmp expect file
61 62 63
'

test_expect_success 'apply stashed changes' '
64 65
	git reset --hard &&
	echo 5 >other-file &&
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
	git add other-file &&
	test_tick &&
	git commit -m other-file &&
	git stash apply &&
	test 3 = $(cat file) &&
	test 1 = $(git show :file) &&
	test 1 = $(git show HEAD:file)
'

test_expect_success 'apply stashed changes (including index)' '
	git reset --hard HEAD^ &&
	echo 6 > other-file &&
	git add other-file &&
	test_tick &&
	git commit -m other-file &&
	git stash apply --index &&
	test 3 = $(cat file) &&
	test 2 = $(git show :file) &&
	test 1 = $(git show HEAD:file)
'

87 88 89
test_expect_success 'unstashing in a subdirectory' '
	git reset --hard HEAD &&
	mkdir subdir &&
90 91 92
	(
		cd subdir &&
		git stash apply
93
	)
94 95
'

J
Jeff King 已提交
96 97 98 99
test_expect_success 'stash drop complains of extra options' '
	test_must_fail git stash drop --foo
'

100 101 102 103 104 105 106
test_expect_success 'drop top stash' '
	git reset --hard &&
	git stash list > stashlist1 &&
	echo 7 > file &&
	git stash &&
	git stash drop &&
	git stash list > stashlist2 &&
107
	test_cmp stashlist1 stashlist2 &&
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
	git stash apply &&
	test 3 = $(cat file) &&
	test 1 = $(git show :file) &&
	test 1 = $(git show HEAD:file)
'

test_expect_success 'drop middle stash' '
	git reset --hard &&
	echo 8 > file &&
	git stash &&
	echo 9 > file &&
	git stash &&
	git stash drop stash@{1} &&
	test 2 = $(git stash list | wc -l) &&
	git stash apply &&
	test 9 = $(cat file) &&
	test 1 = $(git show :file) &&
	test 1 = $(git show HEAD:file) &&
	git reset --hard &&
	git stash drop &&
	git stash apply &&
	test 3 = $(cat file) &&
	test 1 = $(git show :file) &&
	test 1 = $(git show HEAD:file)
'

134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
test_expect_success 'drop middle stash by index' '
	git reset --hard &&
	echo 8 >file &&
	git stash &&
	echo 9 >file &&
	git stash &&
	git stash drop 1 &&
	test 2 = $(git stash list | wc -l) &&
	git stash apply &&
	test 9 = $(cat file) &&
	test 1 = $(git show :file) &&
	test 1 = $(git show HEAD:file) &&
	git reset --hard &&
	git stash drop &&
	git stash apply &&
	test 3 = $(cat file) &&
	test 1 = $(git show :file) &&
	test 1 = $(git show HEAD:file)
'

154 155 156 157 158 159 160
test_expect_success 'stash pop' '
	git reset --hard &&
	git stash pop &&
	test 3 = $(cat file) &&
	test 1 = $(git show :file) &&
	test 1 = $(git show HEAD:file) &&
	test 0 = $(git stash list | wc -l)
161 162
'

163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
cat > expect << EOF
diff --git a/file2 b/file2
new file mode 100644
index 0000000..1fe912c
--- /dev/null
+++ b/file2
@@ -0,0 +1 @@
+bar2
EOF

cat > expect1 << EOF
diff --git a/file b/file
index 257cc56..5716ca5 100644
--- a/file
+++ b/file
@@ -1 +1 @@
-foo
+bar
EOF

cat > expect2 << EOF
diff --git a/file b/file
index 7601807..5716ca5 100644
--- a/file
+++ b/file
@@ -1 +1 @@
-baz
+bar
diff --git a/file2 b/file2
new file mode 100644
index 0000000..1fe912c
--- /dev/null
+++ b/file2
@@ -0,0 +1 @@
+bar2
EOF

test_expect_success 'stash branch' '
	echo foo > file &&
J
Jonathan Nieder 已提交
202
	git commit file -m first &&
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
	echo bar > file &&
	echo bar2 > file2 &&
	git add file2 &&
	git stash &&
	echo baz > file &&
	git commit file -m second &&
	git stash branch stashbranch &&
	test refs/heads/stashbranch = $(git symbolic-ref HEAD) &&
	test $(git rev-parse HEAD) = $(git rev-parse master^) &&
	git diff --cached > output &&
	test_cmp output expect &&
	git diff > output &&
	test_cmp output expect1 &&
	git add file &&
	git commit -m alternate\ second &&
	git diff master..stashbranch > output &&
	test_cmp output expect2 &&
	test 0 = $(git stash list | wc -l)
'

S
Stephen Boyd 已提交
223 224 225 226
test_expect_success 'apply -q is quiet' '
	echo foo > file &&
	git stash &&
	git stash apply -q > output.out 2>&1 &&
J
Junio C Hamano 已提交
227
	test_must_be_empty output.out
S
Stephen Boyd 已提交
228 229 230 231
'

test_expect_success 'save -q is quiet' '
	git stash save --quiet > output.out 2>&1 &&
J
Junio C Hamano 已提交
232
	test_must_be_empty output.out
S
Stephen Boyd 已提交
233 234 235 236
'

test_expect_success 'pop -q is quiet' '
	git stash pop -q > output.out 2>&1 &&
J
Junio C Hamano 已提交
237
	test_must_be_empty output.out
S
Stephen Boyd 已提交
238 239
'

240 241 242 243 244 245
test_expect_success 'pop -q --index works and is quiet' '
	echo foo > file &&
	git add file &&
	git stash save --quiet &&
	git stash pop -q --index > output.out 2>&1 &&
	test foo = "$(git show :file)" &&
J
Junio C Hamano 已提交
246
	test_must_be_empty output.out
247 248
'

S
Stephen Boyd 已提交
249 250 251
test_expect_success 'drop -q is quiet' '
	git stash &&
	git stash drop -q > output.out 2>&1 &&
J
Junio C Hamano 已提交
252
	test_must_be_empty output.out
S
Stephen Boyd 已提交
253 254
'

255 256 257 258 259 260 261 262
test_expect_success 'stash -k' '
	echo bar3 > file &&
	echo bar4 > file2 &&
	git add file2 &&
	git stash -k &&
	test bar,bar4 = $(cat file),$(cat file2)
'

263 264 265 266 267 268 269 270
test_expect_success 'stash --no-keep-index' '
	echo bar33 > file &&
	echo bar44 > file2 &&
	git add file2 &&
	git stash --no-keep-index &&
	test bar,bar2 = $(cat file),$(cat file2)
'

271 272 273 274 275 276 277 278 279 280 281
test_expect_success 'stash --invalid-option' '
	echo bar5 > file &&
	echo bar6 > file2 &&
	git add file2 &&
	test_must_fail git stash --invalid-option &&
	test_must_fail git stash save --invalid-option &&
	test bar5,bar6 = $(cat file),$(cat file2) &&
	git stash -- -message-starting-with-dash &&
	test bar,bar2 = $(cat file),$(cat file2)
'

282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
test_expect_success 'stash an added file' '
	git reset --hard &&
	echo new >file3 &&
	git add file3 &&
	git stash save "added file" &&
	! test -r file3 &&
	git stash apply &&
	test new = "$(cat file3)"
'

test_expect_success 'stash rm then recreate' '
	git reset --hard &&
	git rm file &&
	echo bar7 >file &&
	git stash save "rm then recreate" &&
	test bar = "$(cat file)" &&
	git stash apply &&
	test bar7 = "$(cat file)"
'

test_expect_success 'stash rm and ignore' '
	git reset --hard &&
	git rm file &&
	echo file >.gitignore &&
	git stash save "rm and ignore" &&
	test bar = "$(cat file)" &&
J
Jonathan Nieder 已提交
308
	test file = "$(cat .gitignore)" &&
309 310 311 312 313 314 315 316 317 318 319 320
	git stash apply &&
	! test -r file &&
	test file = "$(cat .gitignore)"
'

test_expect_success 'stash rm and ignore (stage .gitignore)' '
	git reset --hard &&
	git rm file &&
	echo file >.gitignore &&
	git add .gitignore &&
	git stash save "rm and ignore (stage .gitignore)" &&
	test bar = "$(cat file)" &&
J
Jonathan Nieder 已提交
321
	! test -r .gitignore &&
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
	git stash apply &&
	! test -r file &&
	test file = "$(cat .gitignore)"
'

test_expect_success SYMLINKS 'stash file to symlink' '
	git reset --hard &&
	rm file &&
	ln -s file2 file &&
	git stash save "file to symlink" &&
	test -f file &&
	test bar = "$(cat file)" &&
	git stash apply &&
	case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
'

test_expect_success SYMLINKS 'stash file to symlink (stage rm)' '
	git reset --hard &&
	git rm file &&
	ln -s file2 file &&
	git stash save "file to symlink (stage rm)" &&
	test -f file &&
	test bar = "$(cat file)" &&
	git stash apply &&
	case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
'

test_expect_success SYMLINKS 'stash file to symlink (full stage)' '
	git reset --hard &&
	rm file &&
	ln -s file2 file &&
	git add file &&
	git stash save "file to symlink (full stage)" &&
	test -f file &&
	test bar = "$(cat file)" &&
	git stash apply &&
	case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
'

# This test creates a commit with a symlink used for the following tests

363
test_expect_success 'stash symlink to file' '
364
	git reset --hard &&
365
	test_ln_s_add file filelink &&
366 367 368
	git commit -m "Add symlink" &&
	rm filelink &&
	cp file filelink &&
369 370 371 372
	git stash save "symlink to file"
'

test_expect_success SYMLINKS 'this must have re-created the symlink' '
373
	test -h filelink &&
374 375 376 377
	case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
'

test_expect_success 'unstash must re-create the file' '
378 379 380 381 382
	git stash apply &&
	! test -h filelink &&
	test bar = "$(cat file)"
'

383
test_expect_success 'stash symlink to file (stage rm)' '
384 385 386
	git reset --hard &&
	git rm filelink &&
	cp file filelink &&
387 388 389 390
	git stash save "symlink to file (stage rm)"
'

test_expect_success SYMLINKS 'this must have re-created the symlink' '
391
	test -h filelink &&
392 393 394 395
	case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
'

test_expect_success 'unstash must re-create the file' '
396 397 398 399 400
	git stash apply &&
	! test -h filelink &&
	test bar = "$(cat file)"
'

401
test_expect_success 'stash symlink to file (full stage)' '
402 403 404 405
	git reset --hard &&
	rm filelink &&
	cp file filelink &&
	git add filelink &&
406 407 408 409
	git stash save "symlink to file (full stage)"
'

test_expect_success SYMLINKS 'this must have re-created the symlink' '
410
	test -h filelink &&
411 412 413 414
	case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
'

test_expect_success 'unstash must re-create the file' '
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
	git stash apply &&
	! test -h filelink &&
	test bar = "$(cat file)"
'

test_expect_failure 'stash directory to file' '
	git reset --hard &&
	mkdir dir &&
	echo foo >dir/file &&
	git add dir/file &&
	git commit -m "Add file in dir" &&
	rm -fr dir &&
	echo bar >dir &&
	git stash save "directory to file" &&
	test -d dir &&
	test foo = "$(cat dir/file)" &&
	test_must_fail git stash apply &&
	test bar = "$(cat dir)" &&
	git reset --soft HEAD^
'

test_expect_failure 'stash file to directory' '
	git reset --hard &&
	rm file &&
	mkdir file &&
	echo foo >file/file &&
	git stash save "file to directory" &&
	test -f file &&
	test bar = "$(cat file)" &&
	git stash apply &&
	test -f file/file &&
	test foo = "$(cat file/file)"
'

449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
test_expect_success 'stash branch - no stashes on stack, stash-like argument' '
	git stash clear &&
	test_when_finished "git reset --hard HEAD" &&
	git reset --hard &&
	echo foo >> file &&
	STASH_ID=$(git stash create) &&
	git reset --hard &&
	git stash branch stash-branch ${STASH_ID} &&
	test_when_finished "git reset --hard HEAD && git checkout master && git branch -D stash-branch" &&
	test $(git ls-files --modified | wc -l) -eq 1
'

test_expect_success 'stash branch - stashes on stack, stash-like argument' '
	git stash clear &&
	test_when_finished "git reset --hard HEAD" &&
	git reset --hard &&
	echo foo >> file &&
	git stash &&
	test_when_finished "git stash drop" &&
	echo bar >> file &&
	STASH_ID=$(git stash create) &&
	git reset --hard &&
	git stash branch stash-branch ${STASH_ID} &&
	test_when_finished "git reset --hard HEAD && git checkout master && git branch -D stash-branch" &&
	test $(git ls-files --modified | wc -l) -eq 1
'

476
test_expect_success 'stash show format defaults to --stat' '
477 478 479 480 481 482 483 484 485
	git stash clear &&
	test_when_finished "git reset --hard HEAD" &&
	git reset --hard &&
	echo foo >> file &&
	git stash &&
	test_when_finished "git stash drop" &&
	echo bar >> file &&
	STASH_ID=$(git stash create) &&
	git reset --hard &&
486
	cat >expected <<-EOF &&
487
	 file | 1 +
488
	 1 file changed, 1 insertion(+)
489 490
	EOF
	git stash show ${STASH_ID} >actual &&
491
	test_i18ncmp expected actual
492
'
493

494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
test_expect_success 'stash show - stashes on stack, stash-like argument' '
	git stash clear &&
	test_when_finished "git reset --hard HEAD" &&
	git reset --hard &&
	echo foo >> file &&
	git stash &&
	test_when_finished "git stash drop" &&
	echo bar >> file &&
	STASH_ID=$(git stash create) &&
	git reset --hard &&
	echo "1	0	file" >expected &&
	git stash show --numstat ${STASH_ID} >actual &&
	test_cmp expected actual
'

B
Brian Gernhardt 已提交
509
test_expect_success 'stash show -p - stashes on stack, stash-like argument' '
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
	git stash clear &&
	test_when_finished "git reset --hard HEAD" &&
	git reset --hard &&
	echo foo >> file &&
	git stash &&
	test_when_finished "git stash drop" &&
	echo bar >> file &&
	STASH_ID=$(git stash create) &&
	git reset --hard &&
	cat >expected <<-EOF &&
	diff --git a/file b/file
	index 7601807..935fbd3 100644
	--- a/file
	+++ b/file
	@@ -1 +1,2 @@
	 baz
	+bar
	EOF
	git stash show -p ${STASH_ID} >actual &&
	test_cmp expected actual
'

B
Brian Gernhardt 已提交
532
test_expect_success 'stash show - no stashes on stack, stash-like argument' '
533 534 535 536 537 538
	git stash clear &&
	test_when_finished "git reset --hard HEAD" &&
	git reset --hard &&
	echo foo >> file &&
	STASH_ID=$(git stash create) &&
	git reset --hard &&
539 540 541
	echo "1	0	file" >expected &&
	git stash show --numstat ${STASH_ID} >actual &&
	test_cmp expected actual
542 543
'

B
Brian Gernhardt 已提交
544
test_expect_success 'stash show -p - no stashes on stack, stash-like argument' '
545 546 547 548 549 550
	git stash clear &&
	test_when_finished "git reset --hard HEAD" &&
	git reset --hard &&
	echo foo >> file &&
	STASH_ID=$(git stash create) &&
	git reset --hard &&
551 552 553 554 555 556 557 558 559 560 561
	cat >expected <<-EOF &&
	diff --git a/file b/file
	index 7601807..71b52c4 100644
	--- a/file
	+++ b/file
	@@ -1 +1,2 @@
	 baz
	+foo
	EOF
	git stash show -p ${STASH_ID} >actual &&
	test_cmp expected actual
562 563 564 565 566 567 568 569 570 571
'

test_expect_success 'stash drop - fail early if specified stash is not a stash reference' '
	git stash clear &&
	test_when_finished "git reset --hard HEAD && git stash clear" &&
	git reset --hard &&
	echo foo > file &&
	git stash &&
	echo bar > file &&
	git stash &&
572
	test_must_fail git stash drop $(git rev-parse stash@{0}) &&
573 574 575 576 577 578 579 580 581 582 583 584 585
	git stash pop &&
	test bar = "$(cat file)" &&
	git reset --hard HEAD
'

test_expect_success 'stash pop - fail early if specified stash is not a stash reference' '
	git stash clear &&
	test_when_finished "git reset --hard HEAD && git stash clear" &&
	git reset --hard &&
	echo foo > file &&
	git stash &&
	echo bar > file &&
	git stash &&
586
	test_must_fail git stash pop $(git rev-parse stash@{0}) &&
587 588 589 590 591
	git stash pop &&
	test bar = "$(cat file)" &&
	git reset --hard HEAD
'

D
Dmitry Ivankov 已提交
592
test_expect_success 'ref with non-existent reflog' '
593 594 595 596 597
	git stash clear &&
	echo bar5 > file &&
	echo bar6 > file2 &&
	git add file2 &&
	git stash &&
598
	test_must_fail git rev-parse --quiet --verify does-not-exist &&
599 600 601 602 603 604 605 606 607 608
	test_must_fail git stash drop does-not-exist &&
	test_must_fail git stash drop does-not-exist@{0} &&
	test_must_fail git stash pop does-not-exist &&
	test_must_fail git stash pop does-not-exist@{0} &&
	test_must_fail git stash apply does-not-exist &&
	test_must_fail git stash apply does-not-exist@{0} &&
	test_must_fail git stash show does-not-exist &&
	test_must_fail git stash show does-not-exist@{0} &&
	test_must_fail git stash branch tmp does-not-exist &&
	test_must_fail git stash branch tmp does-not-exist@{0} &&
609 610 611 612 613
	git stash drop
'

test_expect_success 'invalid ref of the form stash@{n}, n >= N' '
	git stash clear &&
614
	test_must_fail git stash drop stash@{0} &&
615 616 617 618
	echo bar5 > file &&
	echo bar6 > file2 &&
	git add file2 &&
	git stash &&
619 620 621 622 623
	test_must_fail git stash drop stash@{1} &&
	test_must_fail git stash pop stash@{1} &&
	test_must_fail git stash apply stash@{1} &&
	test_must_fail git stash show stash@{1} &&
	test_must_fail git stash branch tmp stash@{1} &&
624 625 626
	git stash drop
'

627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
test_expect_success 'invalid ref of the form "n", n >= N' '
	git stash clear &&
	test_must_fail git stash drop 0 &&
	echo bar5 >file &&
	echo bar6 >file2 &&
	git add file2 &&
	git stash &&
	test_must_fail git stash drop 1 &&
	test_must_fail git stash pop 1 &&
	test_must_fail git stash apply 1 &&
	test_must_fail git stash show 1 &&
	test_must_fail git stash branch tmp 1 &&
	git stash drop
'

642
test_expect_success 'stash branch should not drop the stash if the branch exists' '
643 644 645 646 647 648 649 650 651 652
	git stash clear &&
	echo foo >file &&
	git add file &&
	git commit -m initial &&
	echo bar >file &&
	git stash &&
	test_must_fail git stash branch master stash@{0} &&
	git rev-parse stash@{0} --
'

653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
test_expect_success 'stash apply shows status same as git status (relative to current directory)' '
	git stash clear &&
	echo 1 >subdir/subfile1 &&
	echo 2 >subdir/subfile2 &&
	git add subdir/subfile1 &&
	git commit -m subdir &&
	(
		cd subdir &&
		echo x >subfile1 &&
		echo x >../file &&
		git status >../expect &&
		git stash &&
		sane_unset GIT_MERGE_VERBOSITY &&
		git stash apply
	) |
	sed -e 1,2d >actual && # drop "Saved..." and "HEAD is now..."
669
	test_i18ncmp expect actual
670 671
'

672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695
cat > expect << EOF
diff --git a/HEAD b/HEAD
new file mode 100644
index 0000000..fe0cbee
--- /dev/null
+++ b/HEAD
@@ -0,0 +1 @@
+file-not-a-ref
EOF

test_expect_success 'stash where working directory contains "HEAD" file' '
	git stash clear &&
	git reset --hard &&
	echo file-not-a-ref > HEAD &&
	git add HEAD &&
	test_tick &&
	git stash &&
	git diff-files --quiet &&
	git diff-index --cached --quiet HEAD &&
	test "$(git rev-parse stash^)" = "$(git rev-parse HEAD)" &&
	git diff stash^..stash > output &&
	test_cmp output expect
'

696 697 698 699 700 701 702 703 704 705 706 707 708 709
test_expect_success 'store called with invalid commit' '
	test_must_fail git stash store foo
'

test_expect_success 'store updates stash ref and reflog' '
	git stash clear &&
	git reset --hard &&
	echo quux >bazzy &&
	git add bazzy &&
	STASH_ID=$(git stash create) &&
	git reset --hard &&
	! grep quux bazzy &&
	git stash store -m quuxery $STASH_ID &&
	test $(cat .git/refs/stash) = $STASH_ID &&
710
	git reflog --format=%H stash| grep $STASH_ID &&
711 712 713 714
	git stash pop &&
	grep quux bazzy
'

715 716 717 718 719 720 721 722 723 724 725 726
test_expect_success 'handle stash specification with spaces' '
	git stash clear &&
	echo pig >file &&
	git stash &&
	stamp=$(git log -g --format="%cd" -1 refs/stash) &&
	test_tick &&
	echo cow >file &&
	git stash &&
	git stash apply "stash@{$stamp}" &&
	grep pig file
'

727 728 729 730 731 732 733 734 735 736
test_expect_success 'setup stash with index and worktree changes' '
	git stash clear &&
	git reset --hard &&
	echo index >file &&
	git add file &&
	echo working >file &&
	git stash
'

test_expect_success 'stash list implies --first-parent -m' '
J
Jeff King 已提交
737 738
	cat >expect <<-EOF &&
	stash@{0}
739 740 741 742 743 744 745 746 747

	diff --git a/file b/file
	index 257cc56..d26b33d 100644
	--- a/file
	+++ b/file
	@@ -1 +1 @@
	-foo
	+working
	EOF
J
Jeff King 已提交
748
	git stash list --format=%gd -p >actual &&
749 750 751 752 753
	test_cmp expect actual
'

test_expect_success 'stash list --cc shows combined diff' '
	cat >expect <<-\EOF &&
J
Jeff King 已提交
754
	stash@{0}
755 756 757 758 759 760 761 762 763 764

	diff --cc file
	index 257cc56,9015a7a..d26b33d
	--- a/file
	+++ b/file
	@@@ -1,1 -1,1 +1,1 @@@
	- foo
	 -index
	++working
	EOF
J
Jeff King 已提交
765
	git stash list --format=%gd -p --cc >actual &&
766 767 768
	test_cmp expect actual
'

J
Jeff King 已提交
769 770 771 772 773 774 775 776 777
test_expect_success 'stash is not confused by partial renames' '
	mv file renamed &&
	git add renamed &&
	git stash &&
	git stash apply &&
	test_path_is_file renamed &&
	test_path_is_missing file
'

778
test_done