Merge branch 'js/commit-graph-warning'
[git/debian.git] / t / t2016-checkout-patch.sh
blobabfd586c32b017e7f00d9cfc1a85cddb4f150d43
1 #!/bin/sh
3 test_description='git checkout --patch'
5 . ./lib-patch-mode.sh
7 test_expect_success PERL 'setup' '
8 mkdir dir &&
9 echo parent > dir/foo &&
10 echo dummy > bar &&
11 git add bar dir/foo &&
12 git commit -m initial &&
13 test_tick &&
14 test_commit second dir/foo head &&
15 set_and_save_state bar bar_work bar_index &&
16 save_head
19 # note: bar sorts before dir/foo, so the first 'n' is always to skip 'bar'
21 # NEEDSWORK: Since the builtin add-p is used when $GIT_TEST_ADD_I_USE_BUILTIN
22 # is given, we should replace the PERL prerequisite with an ADD_I prerequisite
23 # which first checks if $GIT_TEST_ADD_I_USE_BUILTIN is defined before checking
24 # PERL.
25 test_expect_success PERL 'saying "n" does nothing' '
26 set_and_save_state dir/foo work head &&
27 test_write_lines n n | git checkout -p &&
28 verify_saved_state bar &&
29 verify_saved_state dir/foo
32 test_expect_success PERL 'git checkout -p' '
33 test_write_lines n y | git checkout -p &&
34 verify_saved_state bar &&
35 verify_state dir/foo head head
38 test_expect_success PERL 'git checkout -p with staged changes' '
39 set_state dir/foo work index &&
40 test_write_lines n y | git checkout -p &&
41 verify_saved_state bar &&
42 verify_state dir/foo index index
45 test_expect_success PERL 'git checkout -p HEAD with NO staged changes: abort' '
46 set_and_save_state dir/foo work head &&
47 test_write_lines n y n | git checkout -p HEAD &&
48 verify_saved_state bar &&
49 verify_saved_state dir/foo
52 test_expect_success PERL 'git checkout -p HEAD with NO staged changes: apply' '
53 test_write_lines n y y | git checkout -p HEAD &&
54 verify_saved_state bar &&
55 verify_state dir/foo head head
58 test_expect_success PERL 'git checkout -p HEAD with change already staged' '
59 set_state dir/foo index index &&
60 # the third n is to get out in case it mistakenly does not apply
61 test_write_lines n y n | git checkout -p HEAD &&
62 verify_saved_state bar &&
63 verify_state dir/foo head head
66 test_expect_success PERL 'git checkout -p HEAD^...' '
67 # the third n is to get out in case it mistakenly does not apply
68 test_write_lines n y n | git checkout -p HEAD^... &&
69 verify_saved_state bar &&
70 verify_state dir/foo parent parent
73 test_expect_success PERL 'git checkout -p HEAD^' '
74 # the third n is to get out in case it mistakenly does not apply
75 test_write_lines n y n | git checkout -p HEAD^ &&
76 verify_saved_state bar &&
77 verify_state dir/foo parent parent
80 test_expect_success PERL 'git checkout -p handles deletion' '
81 set_state dir/foo work index &&
82 rm dir/foo &&
83 test_write_lines n y | git checkout -p &&
84 verify_saved_state bar &&
85 verify_state dir/foo index index
88 # The idea in the rest is that bar sorts first, so we always say 'y'
89 # first and if the path limiter fails it'll apply to bar instead of
90 # dir/foo. There's always an extra 'n' to reject edits to dir/foo in
91 # the failure case (and thus get out of the loop).
93 test_expect_success PERL 'path limiting works: dir' '
94 set_state dir/foo work head &&
95 test_write_lines y n | git checkout -p dir &&
96 verify_saved_state bar &&
97 verify_state dir/foo head head
100 test_expect_success PERL 'path limiting works: -- dir' '
101 set_state dir/foo work head &&
102 test_write_lines y n | git checkout -p -- dir &&
103 verify_saved_state bar &&
104 verify_state dir/foo head head
107 test_expect_success PERL 'path limiting works: HEAD^ -- dir' '
108 # the third n is to get out in case it mistakenly does not apply
109 test_write_lines y n n | git checkout -p HEAD^ -- dir &&
110 verify_saved_state bar &&
111 verify_state dir/foo parent parent
114 test_expect_success PERL 'path limiting works: foo inside dir' '
115 set_state dir/foo work head &&
116 # the third n is to get out in case it mistakenly does not apply
117 test_write_lines y n n | (cd dir && git checkout -p foo) &&
118 verify_saved_state bar &&
119 verify_state dir/foo head head
122 test_expect_success PERL 'none of this moved HEAD' '
123 verify_saved_head
126 test_expect_success PERL 'empty tree can be handled' '
127 test_when_finished "git reset --hard" &&
128 git checkout -p $(test_oid empty_tree) --
131 test_done