]>
git.ipfire.org Git - thirdparty/git.git/blob - t/t2016-checkout-patch.sh
3 test_description
='git checkout --patch'
7 test_expect_success PERL
'setup' '
9 echo parent > dir/foo &&
11 git add bar dir/foo &&
12 git commit -m initial &&
14 test_commit second dir/foo head &&
15 set_and_save_state bar bar_work bar_index &&
19 # note: bar sorts before dir/foo, so the first 'n' is always to skip 'bar'
21 test_expect_success PERL
'saying "n" does nothing' '
22 set_and_save_state dir/foo work head &&
23 test_write_lines n n | git checkout -p &&
24 verify_saved_state bar &&
25 verify_saved_state dir/foo
28 test_expect_success PERL
'git checkout -p' '
29 test_write_lines n y | git checkout -p &&
30 verify_saved_state bar &&
31 verify_state dir/foo head head
34 test_expect_success PERL
'git checkout -p with staged changes' '
35 set_state dir/foo work index &&
36 test_write_lines n y | git checkout -p &&
37 verify_saved_state bar &&
38 verify_state dir/foo index index
41 test_expect_success PERL
'git checkout -p HEAD with NO staged changes: abort' '
42 set_and_save_state dir/foo work head &&
43 test_write_lines n y n | git checkout -p HEAD &&
44 verify_saved_state bar &&
45 verify_saved_state dir/foo
48 test_expect_success PERL
'git checkout -p HEAD with NO staged changes: apply' '
49 test_write_lines n y y | git checkout -p HEAD &&
50 verify_saved_state bar &&
51 verify_state dir/foo head head
54 test_expect_success PERL
'git checkout -p HEAD with change already staged' '
55 set_state dir/foo index index &&
56 # the third n is to get out in case it mistakenly does not apply
57 test_write_lines n y n | git checkout -p HEAD &&
58 verify_saved_state bar &&
59 verify_state dir/foo head head
62 test_expect_success PERL
'git checkout -p HEAD^' '
63 # the third n is to get out in case it mistakenly does not apply
64 test_write_lines n y n | git checkout -p HEAD^ &&
65 verify_saved_state bar &&
66 verify_state dir/foo parent parent
69 test_expect_success PERL
'git checkout -p handles deletion' '
70 set_state dir/foo work index &&
72 test_write_lines n y | git checkout -p &&
73 verify_saved_state bar &&
74 verify_state dir/foo index index
77 # The idea in the rest is that bar sorts first, so we always say 'y'
78 # first and if the path limiter fails it'll apply to bar instead of
79 # dir/foo. There's always an extra 'n' to reject edits to dir/foo in
80 # the failure case (and thus get out of the loop).
82 test_expect_success PERL
'path limiting works: dir' '
83 set_state dir/foo work head &&
84 test_write_lines y n | git checkout -p dir &&
85 verify_saved_state bar &&
86 verify_state dir/foo head head
89 test_expect_success PERL
'path limiting works: -- dir' '
90 set_state dir/foo work head &&
91 test_write_lines y n | git checkout -p -- dir &&
92 verify_saved_state bar &&
93 verify_state dir/foo head head
96 test_expect_success PERL
'path limiting works: HEAD^ -- dir' '
97 # the third n is to get out in case it mistakenly does not apply
98 test_write_lines y n n | git checkout -p HEAD^ -- dir &&
99 verify_saved_state bar &&
100 verify_state dir/foo parent parent
103 test_expect_success PERL
'path limiting works: foo inside dir' '
104 set_state dir/foo work head &&
105 # the third n is to get out in case it mistakenly does not apply
106 test_write_lines y n n | (cd dir && git checkout -p foo) &&
107 verify_saved_state bar &&
108 verify_state dir/foo head head
111 test_expect_success PERL
'none of this moved HEAD' '