3 test_description
='git reset --patch'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 test_expect_success PERL
'setup' '
10 echo parent > dir/foo &&
13 git commit -m initial &&
15 test_commit second dir/foo head &&
16 set_and_save_state bar bar_work bar_index &&
20 # note: bar sorts before foo, so the first 'n' is always to skip 'bar'
22 test_expect_success PERL
'saying "n" does nothing' '
23 set_and_save_state dir/foo work work &&
24 test_write_lines n n | git reset -p &&
25 verify_saved_state dir/foo &&
26 verify_saved_state bar
29 test_expect_success PERL
'git reset -p' '
30 test_write_lines n y | git reset -p >output &&
31 verify_state dir/foo work head &&
32 verify_saved_state bar &&
33 test_grep "Unstage" output
36 test_expect_success PERL
'git reset -p HEAD^' '
37 test_write_lines n y | git reset -p HEAD^ >output &&
38 verify_state dir/foo work parent &&
39 verify_saved_state bar &&
40 test_grep "Apply" output
43 test_expect_success PERL
'git reset -p HEAD^^{tree}' '
44 test_write_lines n y | git reset -p HEAD^^{tree} >output &&
45 verify_state dir/foo work parent &&
46 verify_saved_state bar &&
47 test_grep "Apply" output
50 test_expect_success PERL
'git reset -p HEAD^:dir/foo (blob fails)' '
51 set_and_save_state dir/foo work work &&
52 test_must_fail git reset -p HEAD^:dir/foo &&
53 verify_saved_state dir/foo &&
54 verify_saved_state bar
57 test_expect_success PERL
'git reset -p aaaaaaaa (unknown fails)' '
58 set_and_save_state dir/foo work work &&
59 test_must_fail git reset -p aaaaaaaa &&
60 verify_saved_state dir/foo &&
61 verify_saved_state bar
64 # The idea in the rest is that bar sorts first, so we always say 'y'
65 # first and if the path limiter fails it'll apply to bar instead of
66 # dir/foo. There's always an extra 'n' to reject edits to dir/foo in
67 # the failure case (and thus get out of the loop).
69 test_expect_success PERL
'git reset -p dir' '
70 set_state dir/foo work work &&
71 test_write_lines y n | git reset -p dir &&
72 verify_state dir/foo work head &&
73 verify_saved_state bar
76 test_expect_success PERL
'git reset -p -- foo (inside dir)' '
77 set_state dir/foo work work &&
78 test_write_lines y n | (cd dir && git reset -p -- foo) &&
79 verify_state dir/foo work head &&
80 verify_saved_state bar
83 test_expect_success PERL
'git reset -p HEAD^ -- dir' '
84 test_write_lines y n | git reset -p HEAD^ -- dir &&
85 verify_state dir/foo work parent &&
86 verify_saved_state bar
89 test_expect_success PERL
'none of this moved HEAD' '