Merge branch 'rj/cygwin-has-dev-tty'
[git/gitster.git] / t / t7105-reset-patch.sh
blobf4f3b7a677aa16539f8277ce3d4132ade0b17168
1 #!/bin/sh
3 test_description='git reset --patch'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./lib-patch-mode.sh
8 test_expect_success 'setup' '
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
20 # note: bar sorts before foo, so the first 'n' is always to skip 'bar'
22 test_expect_success '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 for opt in "HEAD" "@" ""
31 test_expect_success "git reset -p $opt" '
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
38 done
40 test_expect_success 'git reset -p HEAD^' '
41 test_write_lines n y | git reset -p HEAD^ >output &&
42 verify_state dir/foo work parent &&
43 verify_saved_state bar &&
44 test_grep "Apply" output
47 test_expect_success 'git reset -p HEAD^^{tree}' '
48 test_write_lines n y | git reset -p HEAD^^{tree} >output &&
49 verify_state dir/foo work parent &&
50 verify_saved_state bar &&
51 test_grep "Apply" output
54 test_expect_success 'git reset -p HEAD^:dir/foo (blob fails)' '
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
61 test_expect_success 'git reset -p aaaaaaaa (unknown fails)' '
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
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).
73 test_expect_success 'git reset -p dir' '
74 set_state dir/foo work work &&
75 test_write_lines y n | git reset -p dir &&
76 verify_state dir/foo work head &&
77 verify_saved_state bar
80 test_expect_success 'git reset -p -- foo (inside dir)' '
81 set_state dir/foo work work &&
82 test_write_lines y n | (cd dir && git reset -p -- foo) &&
83 verify_state dir/foo work head &&
84 verify_saved_state bar
87 test_expect_success 'git reset -p HEAD^ -- dir' '
88 test_write_lines y n | git reset -p HEAD^ -- dir &&
89 verify_state dir/foo work parent &&
90 verify_saved_state bar
93 test_expect_success 'none of this moved HEAD' '
94 verify_saved_head
98 test_done