]>
Commit | Line | Data |
---|---|---|
d002ef4d TR |
1 | #!/bin/sh |
2 | ||
3 | test_description='git reset --patch' | |
7615cf94 ÆAB |
4 | |
5 | TEST_PASSES_SANITIZE_LEAK=true | |
d002ef4d TR |
6 | . ./lib-patch-mode.sh |
7 | ||
7abc1869 | 8 | test_expect_success 'setup' ' |
d002ef4d TR |
9 | mkdir dir && |
10 | echo parent > dir/foo && | |
11 | echo dummy > bar && | |
12 | git add dir && | |
13 | git commit -m initial && | |
14 | test_tick && | |
15 | test_commit second dir/foo head && | |
16 | set_and_save_state bar bar_work bar_index && | |
17 | save_head | |
18 | ' | |
19 | ||
20 | # note: bar sorts before foo, so the first 'n' is always to skip 'bar' | |
21 | ||
7abc1869 | 22 | test_expect_success 'saying "n" does nothing' ' |
a48fcd83 | 23 | set_and_save_state dir/foo work work && |
0590ff26 | 24 | test_write_lines n n | git reset -p && |
d002ef4d TR |
25 | verify_saved_state dir/foo && |
26 | verify_saved_state bar | |
27 | ' | |
28 | ||
5a8ed3fe GT |
29 | for opt in "HEAD" "@" "" |
30 | do | |
7abc1869 | 31 | test_expect_success "git reset -p $opt" ' |
5a8ed3fe GT |
32 | set_and_save_state dir/foo work work && |
33 | test_write_lines n y | git reset -p $opt >output && | |
34 | verify_state dir/foo work head && | |
35 | verify_saved_state bar && | |
36 | test_grep "Unstage" output | |
37 | ' | |
38 | done | |
d002ef4d | 39 | |
7abc1869 | 40 | test_expect_success 'git reset -p HEAD^' ' |
0590ff26 | 41 | test_write_lines n y | git reset -p HEAD^ >output && |
d002ef4d | 42 | verify_state dir/foo work parent && |
b3e9ce13 | 43 | verify_saved_state bar && |
6789275d | 44 | test_grep "Apply" output |
d002ef4d TR |
45 | ' |
46 | ||
7abc1869 | 47 | test_expect_success 'git reset -p HEAD^^{tree}' ' |
0a8e3036 NL |
48 | test_write_lines n y | git reset -p HEAD^^{tree} >output && |
49 | verify_state dir/foo work parent && | |
50 | verify_saved_state bar && | |
6789275d | 51 | test_grep "Apply" output |
0a8e3036 NL |
52 | ' |
53 | ||
7abc1869 | 54 | test_expect_success 'git reset -p HEAD^:dir/foo (blob fails)' ' |
0a8e3036 NL |
55 | set_and_save_state dir/foo work work && |
56 | test_must_fail git reset -p HEAD^:dir/foo && | |
57 | verify_saved_state dir/foo && | |
58 | verify_saved_state bar | |
59 | ' | |
60 | ||
7abc1869 | 61 | test_expect_success 'git reset -p aaaaaaaa (unknown fails)' ' |
0a8e3036 NL |
62 | set_and_save_state dir/foo work work && |
63 | test_must_fail git reset -p aaaaaaaa && | |
64 | verify_saved_state dir/foo && | |
65 | verify_saved_state bar | |
66 | ' | |
67 | ||
d002ef4d TR |
68 | # The idea in the rest is that bar sorts first, so we always say 'y' |
69 | # first and if the path limiter fails it'll apply to bar instead of | |
70 | # dir/foo. There's always an extra 'n' to reject edits to dir/foo in | |
71 | # the failure case (and thus get out of the loop). | |
72 | ||
7abc1869 | 73 | test_expect_success 'git reset -p dir' ' |
a48fcd83 | 74 | set_state dir/foo work work && |
0590ff26 | 75 | test_write_lines y n | git reset -p dir && |
d002ef4d TR |
76 | verify_state dir/foo work head && |
77 | verify_saved_state bar | |
78 | ' | |
79 | ||
7abc1869 | 80 | test_expect_success 'git reset -p -- foo (inside dir)' ' |
a48fcd83 | 81 | set_state dir/foo work work && |
0590ff26 | 82 | test_write_lines y n | (cd dir && git reset -p -- foo) && |
d002ef4d TR |
83 | verify_state dir/foo work head && |
84 | verify_saved_state bar | |
85 | ' | |
86 | ||
7abc1869 | 87 | test_expect_success 'git reset -p HEAD^ -- dir' ' |
0590ff26 | 88 | test_write_lines y n | git reset -p HEAD^ -- dir && |
d002ef4d TR |
89 | verify_state dir/foo work parent && |
90 | verify_saved_state bar | |
91 | ' | |
92 | ||
7abc1869 | 93 | test_expect_success 'none of this moved HEAD' ' |
d002ef4d TR |
94 | verify_saved_head |
95 | ' | |
96 | ||
97 | ||
98 | test_done |