]> git.ipfire.org Git - thirdparty/git.git/blob - t/t7105-reset-patch.sh
Merge branch 'jk/bundle-use-dash-for-stdfiles'
[thirdparty/git.git] / t / t7105-reset-patch.sh
1 #!/bin/sh
2
3 test_description='git reset --patch'
4
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./lib-patch-mode.sh
7
8 test_expect_success PERL '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
18 '
19
20 # note: bar sorts before foo, so the first 'n' is always to skip 'bar'
21
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
27 '
28
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_i18ngrep "Unstage" output
34 '
35
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_i18ngrep "Apply" output
41 '
42
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_i18ngrep "Apply" output
48 '
49
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
55 '
56
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
62 '
63
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).
68
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
74 '
75
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
81 '
82
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
87 '
88
89 test_expect_success PERL 'none of this moved HEAD' '
90 verify_saved_head
91 '
92
93
94 test_done