]>
Commit | Line | Data |
---|---|---|
d002ef4d TR |
1 | #!/bin/sh |
2 | ||
3 | test_description='git reset --patch' | |
4 | . ./lib-patch-mode.sh | |
5 | ||
d2b263cb | 6 | test_expect_success PERL 'setup' ' |
d002ef4d TR |
7 | mkdir dir && |
8 | echo parent > dir/foo && | |
9 | echo dummy > bar && | |
10 | git add dir && | |
11 | git commit -m initial && | |
12 | test_tick && | |
13 | test_commit second dir/foo head && | |
14 | set_and_save_state bar bar_work bar_index && | |
15 | save_head | |
16 | ' | |
17 | ||
18 | # note: bar sorts before foo, so the first 'n' is always to skip 'bar' | |
19 | ||
d2b263cb | 20 | test_expect_success PERL 'saying "n" does nothing' ' |
a48fcd83 | 21 | set_and_save_state dir/foo work work && |
d002ef4d TR |
22 | (echo n; echo n) | git reset -p && |
23 | verify_saved_state dir/foo && | |
24 | verify_saved_state bar | |
25 | ' | |
26 | ||
d2b263cb | 27 | test_expect_success PERL 'git reset -p' ' |
d002ef4d TR |
28 | (echo n; echo y) | git reset -p && |
29 | verify_state dir/foo work head && | |
30 | verify_saved_state bar | |
31 | ' | |
32 | ||
d2b263cb | 33 | test_expect_success PERL 'git reset -p HEAD^' ' |
d002ef4d TR |
34 | (echo n; echo y) | git reset -p HEAD^ && |
35 | verify_state dir/foo work parent && | |
36 | verify_saved_state bar | |
37 | ' | |
38 | ||
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). | |
43 | ||
f2f7b6a5 | 44 | test_expect_success PERL 'git reset -p dir' ' |
a48fcd83 | 45 | set_state dir/foo work work && |
d002ef4d TR |
46 | (echo y; echo n) | git reset -p dir && |
47 | verify_state dir/foo work head && | |
48 | verify_saved_state bar | |
49 | ' | |
50 | ||
f2f7b6a5 | 51 | test_expect_success PERL 'git reset -p -- foo (inside dir)' ' |
a48fcd83 | 52 | set_state dir/foo work work && |
d002ef4d TR |
53 | (echo y; echo n) | (cd dir && git reset -p -- foo) && |
54 | verify_state dir/foo work head && | |
55 | verify_saved_state bar | |
56 | ' | |
57 | ||
f2f7b6a5 | 58 | test_expect_success PERL 'git reset -p HEAD^ -- dir' ' |
d002ef4d TR |
59 | (echo y; echo n) | git reset -p HEAD^ -- dir && |
60 | verify_state dir/foo work parent && | |
61 | verify_saved_state bar | |
62 | ' | |
63 | ||
f2f7b6a5 | 64 | test_expect_success PERL 'none of this moved HEAD' ' |
d002ef4d TR |
65 | verify_saved_head |
66 | ' | |
67 | ||
68 | ||
69 | test_done |