]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3904-stash-patch.sh
path.c: don't call the match function without value in trie_find()
[thirdparty/git.git] / t / t3904-stash-patch.sh
CommitLineData
dda1f2a5
TR
1#!/bin/sh
2
470b11e8 3test_description='stash -p'
dda1f2a5
TR
4. ./lib-patch-mode.sh
5
798a5b03
MM
6if ! test_have_prereq PERL
7then
8 skip_all='skipping stash -p tests, perl not available'
9 test_done
10fi
11
12test_expect_success 'setup' '
dda1f2a5
TR
13 mkdir dir &&
14 echo parent > dir/foo &&
15 echo dummy > bar &&
44df2e29
JM
16 echo committed > HEAD &&
17 git add bar dir/foo HEAD &&
dda1f2a5
TR
18 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
44df2e29 27# note: order of files with unstaged changes: HEAD bar dir/foo
dda1f2a5 28
798a5b03 29test_expect_success 'saying "n" does nothing' '
44df2e29 30 set_state HEAD HEADfile_work HEADfile_index &&
a48fcd83 31 set_state dir/foo work index &&
0590ff26 32 test_write_lines n n n | test_must_fail git stash save -p &&
44df2e29
JM
33 verify_state HEAD HEADfile_work HEADfile_index &&
34 verify_saved_state bar &&
35 verify_state dir/foo work index
dda1f2a5
TR
36'
37
798a5b03 38test_expect_success 'git stash -p' '
0590ff26 39 test_write_lines y n y | git stash save -p &&
44df2e29 40 verify_state HEAD committed HEADfile_index &&
dda1f2a5 41 verify_saved_state bar &&
44df2e29 42 verify_state dir/foo head index &&
dda1f2a5
TR
43 git reset --hard &&
44 git stash apply &&
44df2e29
JM
45 verify_state HEAD HEADfile_work committed &&
46 verify_state bar dummy dummy &&
47 verify_state dir/foo work head
dda1f2a5
TR
48'
49
798a5b03 50test_expect_success 'git stash -p --no-keep-index' '
44df2e29 51 set_state HEAD HEADfile_work HEADfile_index &&
dda1f2a5 52 set_state bar bar_work bar_index &&
44df2e29 53 set_state dir/foo work index &&
0590ff26 54 test_write_lines y n y | git stash save -p --no-keep-index &&
44df2e29 55 verify_state HEAD committed committed &&
dda1f2a5 56 verify_state bar bar_work dummy &&
44df2e29 57 verify_state dir/foo head head &&
dda1f2a5
TR
58 git reset --hard &&
59 git stash apply --index &&
44df2e29
JM
60 verify_state HEAD HEADfile_work HEADfile_index &&
61 verify_state bar dummy bar_index &&
62 verify_state dir/foo work index
dda1f2a5
TR
63'
64
798a5b03 65test_expect_success 'git stash --no-keep-index -p' '
44df2e29 66 set_state HEAD HEADfile_work HEADfile_index &&
21ec98a7 67 set_state bar bar_work bar_index &&
44df2e29 68 set_state dir/foo work index &&
0590ff26 69 test_write_lines y n y | git stash save --no-keep-index -p &&
44df2e29 70 verify_state HEAD committed committed &&
21ec98a7
DM
71 verify_state dir/foo head head &&
72 verify_state bar bar_work dummy &&
73 git reset --hard &&
74 git stash apply --index &&
44df2e29
JM
75 verify_state HEAD HEADfile_work HEADfile_index &&
76 verify_state bar dummy bar_index &&
77 verify_state dir/foo work index
21ec98a7
DM
78'
79
869fb8f7
TG
80test_expect_success 'stash -p --no-keep-index -- <pathspec> does not unstage other files' '
81 set_state HEAD HEADfile_work HEADfile_index &&
82 set_state dir/foo work index &&
83 echo y | git stash push -p --no-keep-index -- HEAD &&
84 verify_state HEAD committed committed &&
85 verify_state dir/foo work index
86'
87
798a5b03 88test_expect_success 'none of this moved HEAD' '
dda1f2a5
TR
89 verify_saved_head
90'
91
7e9e0486
MM
92test_expect_failure 'stash -p with split hunk' '
93 git reset --hard &&
94 cat >test <<-\EOF &&
95 aaa
96 bbb
97 ccc
98 EOF
99 git add test &&
100 git commit -m "initial" &&
101 cat >test <<-\EOF &&
102 aaa
103 added line 1
104 bbb
105 added line 2
106 ccc
107 EOF
108 printf "%s\n" s n y q |
109 test_might_fail git stash -p 2>error &&
110 ! test_must_be_empty error &&
111 grep "added line 1" test &&
112 ! grep "added line 2" test
113'
114
dda1f2a5 115test_done