Merge branch 'ar/submodule-add-config'
[git/debian.git] / t / t7105-reset-patch.sh
blobfc2a6cf5c7a49a7971e23213d4d324799c2f92c9
1 #!/bin/sh
3 test_description='git reset --patch'
4 . ./lib-patch-mode.sh
6 test_expect_success PERL 'setup' '
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
18 # note: bar sorts before foo, so the first 'n' is always to skip 'bar'
20 test_expect_success PERL 'saying "n" does nothing' '
21 set_and_save_state dir/foo work work &&
22 test_write_lines n n | git reset -p &&
23 verify_saved_state dir/foo &&
24 verify_saved_state bar
27 test_expect_success PERL 'git reset -p' '
28 test_write_lines n y | git reset -p >output &&
29 verify_state dir/foo work head &&
30 verify_saved_state bar &&
31 test_i18ngrep "Unstage" output
34 test_expect_success PERL 'git reset -p HEAD^' '
35 test_write_lines n y | git reset -p HEAD^ >output &&
36 verify_state dir/foo work parent &&
37 verify_saved_state bar &&
38 test_i18ngrep "Apply" output
41 test_expect_success PERL 'git reset -p HEAD^^{tree}' '
42 test_write_lines n y | git reset -p HEAD^^{tree} >output &&
43 verify_state dir/foo work parent &&
44 verify_saved_state bar &&
45 test_i18ngrep "Apply" output
48 test_expect_success PERL 'git reset -p HEAD^:dir/foo (blob fails)' '
49 set_and_save_state dir/foo work work &&
50 test_must_fail git reset -p HEAD^:dir/foo &&
51 verify_saved_state dir/foo &&
52 verify_saved_state bar
55 test_expect_success PERL 'git reset -p aaaaaaaa (unknown fails)' '
56 set_and_save_state dir/foo work work &&
57 test_must_fail git reset -p aaaaaaaa &&
58 verify_saved_state dir/foo &&
59 verify_saved_state bar
62 # The idea in the rest is that bar sorts first, so we always say 'y'
63 # first and if the path limiter fails it'll apply to bar instead of
64 # dir/foo. There's always an extra 'n' to reject edits to dir/foo in
65 # the failure case (and thus get out of the loop).
67 test_expect_success PERL 'git reset -p dir' '
68 set_state dir/foo work work &&
69 test_write_lines y n | git reset -p dir &&
70 verify_state dir/foo work head &&
71 verify_saved_state bar
74 test_expect_success PERL 'git reset -p -- foo (inside dir)' '
75 set_state dir/foo work work &&
76 test_write_lines y n | (cd dir && git reset -p -- foo) &&
77 verify_state dir/foo work head &&
78 verify_saved_state bar
81 test_expect_success PERL 'git reset -p HEAD^ -- dir' '
82 test_write_lines y n | git reset -p HEAD^ -- dir &&
83 verify_state dir/foo work parent &&
84 verify_saved_state bar
87 test_expect_success PERL 'none of this moved HEAD' '
88 verify_saved_head
92 test_done