blob: 38e730090fe311ea82c737646aedba214d1143bb [file] [log] [blame]
Thomas Rastdda1f2a2009-08-13 14:29:44 +02001#!/bin/sh
2
Matthieu Moy470b11e2015-04-16 09:02:29 +02003test_description='stash -p'
Thomas Rastdda1f2a2009-08-13 14:29:44 +02004. ./lib-patch-mode.sh
5
Matthieu Moy798a5b02015-04-16 09:02:30 +02006if ! test_have_prereq PERL
7then
8 skip_all='skipping stash -p tests, perl not available'
9 test_done
10fi
11
12test_expect_success 'setup' '
Thomas Rastdda1f2a2009-08-13 14:29:44 +020013 mkdir dir &&
14 echo parent > dir/foo &&
15 echo dummy > bar &&
Jonathon Mah44df2e22011-12-30 16:14:01 -080016 echo committed > HEAD &&
17 git add bar dir/foo HEAD &&
Thomas Rastdda1f2a2009-08-13 14:29:44 +020018 git commit -m initial &&
19 test_tick &&
20 test_commit second dir/foo head &&
21 echo index > dir/foo &&
22 git add dir/foo &&
23 set_and_save_state bar bar_work bar_index &&
24 save_head
25'
26
Jonathon Mah44df2e22011-12-30 16:14:01 -080027# note: order of files with unstaged changes: HEAD bar dir/foo
Thomas Rastdda1f2a2009-08-13 14:29:44 +020028
Matthieu Moy798a5b02015-04-16 09:02:30 +020029test_expect_success 'saying "n" does nothing' '
Jonathon Mah44df2e22011-12-30 16:14:01 -080030 set_state HEAD HEADfile_work HEADfile_index &&
Jonathan Niedera48fcd82010-10-30 20:46:54 -050031 set_state dir/foo work index &&
Jonathon Mah44df2e22011-12-30 16:14:01 -080032 (echo n; echo n; echo n) | test_must_fail git stash save -p &&
33 verify_state HEAD HEADfile_work HEADfile_index &&
34 verify_saved_state bar &&
35 verify_state dir/foo work index
Thomas Rastdda1f2a2009-08-13 14:29:44 +020036'
37
Matthieu Moy798a5b02015-04-16 09:02:30 +020038test_expect_success 'git stash -p' '
Jonathon Mah44df2e22011-12-30 16:14:01 -080039 (echo y; echo n; echo y) | git stash save -p &&
40 verify_state HEAD committed HEADfile_index &&
Thomas Rastdda1f2a2009-08-13 14:29:44 +020041 verify_saved_state bar &&
Jonathon Mah44df2e22011-12-30 16:14:01 -080042 verify_state dir/foo head index &&
Thomas Rastdda1f2a2009-08-13 14:29:44 +020043 git reset --hard &&
44 git stash apply &&
Jonathon Mah44df2e22011-12-30 16:14:01 -080045 verify_state HEAD HEADfile_work committed &&
46 verify_state bar dummy dummy &&
47 verify_state dir/foo work head
Thomas Rastdda1f2a2009-08-13 14:29:44 +020048'
49
Matthieu Moy798a5b02015-04-16 09:02:30 +020050test_expect_success 'git stash -p --no-keep-index' '
Jonathon Mah44df2e22011-12-30 16:14:01 -080051 set_state HEAD HEADfile_work HEADfile_index &&
Thomas Rastdda1f2a2009-08-13 14:29:44 +020052 set_state bar bar_work bar_index &&
Jonathon Mah44df2e22011-12-30 16:14:01 -080053 set_state dir/foo work index &&
54 (echo y; echo n; echo y) | git stash save -p --no-keep-index &&
55 verify_state HEAD committed committed &&
Thomas Rastdda1f2a2009-08-13 14:29:44 +020056 verify_state bar bar_work dummy &&
Jonathon Mah44df2e22011-12-30 16:14:01 -080057 verify_state dir/foo head head &&
Thomas Rastdda1f2a2009-08-13 14:29:44 +020058 git reset --hard &&
59 git stash apply --index &&
Jonathon Mah44df2e22011-12-30 16:14:01 -080060 verify_state HEAD HEADfile_work HEADfile_index &&
61 verify_state bar dummy bar_index &&
62 verify_state dir/foo work index
Thomas Rastdda1f2a2009-08-13 14:29:44 +020063'
64
Matthieu Moy798a5b02015-04-16 09:02:30 +020065test_expect_success 'git stash --no-keep-index -p' '
Jonathon Mah44df2e22011-12-30 16:14:01 -080066 set_state HEAD HEADfile_work HEADfile_index &&
Dan McGee21ec98a2011-04-07 12:04:19 -050067 set_state bar bar_work bar_index &&
Jonathon Mah44df2e22011-12-30 16:14:01 -080068 set_state dir/foo work index &&
69 (echo y; echo n; echo y) | git stash save --no-keep-index -p &&
70 verify_state HEAD committed committed &&
Dan McGee21ec98a2011-04-07 12:04:19 -050071 verify_state dir/foo head head &&
72 verify_state bar bar_work dummy &&
73 git reset --hard &&
74 git stash apply --index &&
Jonathon Mah44df2e22011-12-30 16:14:01 -080075 verify_state HEAD HEADfile_work HEADfile_index &&
76 verify_state bar dummy bar_index &&
77 verify_state dir/foo work index
Dan McGee21ec98a2011-04-07 12:04:19 -050078'
79
Matthieu Moy798a5b02015-04-16 09:02:30 +020080test_expect_success 'none of this moved HEAD' '
Thomas Rastdda1f2a2009-08-13 14:29:44 +020081 verify_saved_head
82'
83
Matthieu Moy7e9e0482015-04-16 09:02:31 +020084test_expect_failure 'stash -p with split hunk' '
85 git reset --hard &&
86 cat >test <<-\EOF &&
87 aaa
88 bbb
89 ccc
90 EOF
91 git add test &&
92 git commit -m "initial" &&
93 cat >test <<-\EOF &&
94 aaa
95 added line 1
96 bbb
97 added line 2
98 ccc
99 EOF
100 printf "%s\n" s n y q |
101 test_might_fail git stash -p 2>error &&
102 ! test_must_be_empty error &&
103 grep "added line 1" test &&
104 ! grep "added line 2" test
105'
106
Thomas Rastdda1f2a2009-08-13 14:29:44 +0200107test_done