3 test_description='git reset --patch'
6 test_expect_success 'setup' '
8 echo parent > dir/foo &&
11 git commit -m initial &&
13 test_commit second dir/foo head &&
14 set_and_save_state bar bar_work bar_index &&
18 # note: bar sorts before foo, so the first 'n' is always to skip 'bar'
20 test_expect_success 'saying "n" does nothing' '
21 set_and_save_state dir/foo work work
22 (echo n; echo n) | git reset -p &&
23 verify_saved_state dir/foo &&
24 verify_saved_state bar
27 test_expect_success 'git reset -p' '
28 (echo n; echo y) | git reset -p &&
29 verify_state dir/foo work head &&
30 verify_saved_state bar
33 test_expect_success 'git reset -p HEAD^' '
34 (echo n; echo y) | git reset -p HEAD^ &&
35 verify_state dir/foo work parent &&
36 verify_saved_state bar
39 # The idea in the rest is that bar sorts first, so we always say 'y'
40 # first and if the path limiter fails it'll apply to bar instead of
41 # dir/foo. There's always an extra 'n' to reject edits to dir/foo in
42 # the failure case (and thus get out of the loop).
44 test_expect_success PERL 'git reset -p dir' '
45 set_state dir/foo work work
46 (echo y; echo n) | git reset -p dir &&
47 verify_state dir/foo work head &&
48 verify_saved_state bar
51 test_expect_success PERL 'git reset -p -- foo (inside dir)' '
52 set_state dir/foo work work
53 (echo y; echo n) | (cd dir && git reset -p -- foo) &&
54 verify_state dir/foo work head &&
55 verify_saved_state bar
58 test_expect_success PERL 'git reset -p HEAD^ -- dir' '
59 (echo y; echo n) | git reset -p HEAD^ -- dir &&
60 verify_state dir/foo work parent &&
61 verify_saved_state bar
64 test_expect_success PERL 'none of this moved HEAD' '