t5559: fix test failures with LIB_HTTPD_SSL
[git/debian.git] / t / t2016-checkout-patch.sh
bloba5822e41af28112d44f8a2076804a5dd7d197904
1 #!/bin/sh
3 test_description='git checkout --patch'
5 . ./lib-patch-mode.sh
7 if ! test_have_prereq ADD_I_USE_BUILTIN && ! test_have_prereq PERL
8 then
9 skip_all='skipping interactive add tests, PERL not set'
10 test_done
13 test_expect_success 'setup' '
14 mkdir dir &&
15 echo parent > dir/foo &&
16 echo dummy > bar &&
17 git add bar dir/foo &&
18 git commit -m initial &&
19 test_tick &&
20 test_commit second dir/foo head &&
21 set_and_save_state bar bar_work bar_index &&
22 save_head
25 # note: bar sorts before dir/foo, so the first 'n' is always to skip 'bar'
27 test_expect_success 'saying "n" does nothing' '
28 set_and_save_state dir/foo work head &&
29 test_write_lines n n | git checkout -p &&
30 verify_saved_state bar &&
31 verify_saved_state dir/foo
34 test_expect_success 'git checkout -p' '
35 test_write_lines n y | git checkout -p &&
36 verify_saved_state bar &&
37 verify_state dir/foo head head
40 test_expect_success 'git checkout -p with staged changes' '
41 set_state dir/foo work index &&
42 test_write_lines n y | git checkout -p &&
43 verify_saved_state bar &&
44 verify_state dir/foo index index
47 test_expect_success 'git checkout -p HEAD with NO staged changes: abort' '
48 set_and_save_state dir/foo work head &&
49 test_write_lines n y n | git checkout -p HEAD &&
50 verify_saved_state bar &&
51 verify_saved_state dir/foo
54 test_expect_success 'git checkout -p HEAD with NO staged changes: apply' '
55 test_write_lines n y y | git checkout -p HEAD &&
56 verify_saved_state bar &&
57 verify_state dir/foo head head
60 test_expect_success 'git checkout -p HEAD with change already staged' '
61 set_state dir/foo index index &&
62 # the third n is to get out in case it mistakenly does not apply
63 test_write_lines n y n | git checkout -p HEAD &&
64 verify_saved_state bar &&
65 verify_state dir/foo head head
68 test_expect_success 'git checkout -p HEAD^...' '
69 # the third n is to get out in case it mistakenly does not apply
70 test_write_lines n y n | git checkout -p HEAD^... &&
71 verify_saved_state bar &&
72 verify_state dir/foo parent parent
75 test_expect_success 'git checkout -p HEAD^' '
76 # the third n is to get out in case it mistakenly does not apply
77 test_write_lines n y n | git checkout -p HEAD^ &&
78 verify_saved_state bar &&
79 verify_state dir/foo parent parent
82 test_expect_success 'git checkout -p handles deletion' '
83 set_state dir/foo work index &&
84 rm dir/foo &&
85 test_write_lines n y | git checkout -p &&
86 verify_saved_state bar &&
87 verify_state dir/foo index index
90 # The idea in the rest is that bar sorts first, so we always say 'y'
91 # first and if the path limiter fails it'll apply to bar instead of
92 # dir/foo. There's always an extra 'n' to reject edits to dir/foo in
93 # the failure case (and thus get out of the loop).
95 test_expect_success 'path limiting works: dir' '
96 set_state dir/foo work head &&
97 test_write_lines y n | git checkout -p dir &&
98 verify_saved_state bar &&
99 verify_state dir/foo head head
102 test_expect_success 'path limiting works: -- dir' '
103 set_state dir/foo work head &&
104 test_write_lines y n | git checkout -p -- dir &&
105 verify_saved_state bar &&
106 verify_state dir/foo head head
109 test_expect_success 'path limiting works: HEAD^ -- dir' '
110 # the third n is to get out in case it mistakenly does not apply
111 test_write_lines y n n | git checkout -p HEAD^ -- dir &&
112 verify_saved_state bar &&
113 verify_state dir/foo parent parent
116 test_expect_success 'path limiting works: foo inside dir' '
117 set_state dir/foo work head &&
118 # the third n is to get out in case it mistakenly does not apply
119 test_write_lines y n n | (cd dir && git checkout -p foo) &&
120 verify_saved_state bar &&
121 verify_state dir/foo head head
124 test_expect_success 'none of this moved HEAD' '
125 verify_saved_head
128 test_expect_success 'empty tree can be handled' '
129 test_when_finished "git reset --hard" &&
130 git checkout -p $(test_oid empty_tree) --
133 test_done