]>
Commit | Line | Data |
---|---|---|
4df3ec63 NTND |
1 | #!/bin/sh |
2 | ||
3 | test_description='git restore --patch' | |
4 | ||
2f64da07 | 5 | TEST_PASSES_SANITIZE_LEAK=true |
4df3ec63 NTND |
6 | . ./lib-patch-mode.sh |
7 | ||
7abc1869 | 8 | test_expect_success 'setup' ' |
4df3ec63 NTND |
9 | mkdir dir && |
10 | echo parent >dir/foo && | |
11 | echo dummy >bar && | |
12 | git add bar dir/foo && | |
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 | ||
7abc1869 | 20 | test_expect_success 'restore -p without pathspec is fine' ' |
4df3ec63 NTND |
21 | echo q >cmd && |
22 | git restore -p <cmd | |
23 | ' | |
24 | ||
25 | # note: bar sorts before dir/foo, so the first 'n' is always to skip 'bar' | |
26 | ||
7abc1869 | 27 | test_expect_success 'saying "n" does nothing' ' |
4df3ec63 NTND |
28 | set_and_save_state dir/foo work head && |
29 | test_write_lines n n | git restore -p && | |
30 | verify_saved_state bar && | |
31 | verify_saved_state dir/foo | |
32 | ' | |
33 | ||
7abc1869 | 34 | test_expect_success 'git restore -p' ' |
4df3ec63 NTND |
35 | set_and_save_state dir/foo work head && |
36 | test_write_lines n y | git restore -p && | |
37 | verify_saved_state bar && | |
38 | verify_state dir/foo head head | |
39 | ' | |
40 | ||
7abc1869 | 41 | test_expect_success 'git restore -p with staged changes' ' |
4df3ec63 NTND |
42 | set_state dir/foo work index && |
43 | test_write_lines n y | git restore -p && | |
44 | verify_saved_state bar && | |
45 | verify_state dir/foo index index | |
46 | ' | |
47 | ||
5a8ed3fe GT |
48 | for opt in "HEAD" "@" |
49 | do | |
7abc1869 | 50 | test_expect_success "git restore -p --source=$opt" ' |
5a8ed3fe GT |
51 | set_state dir/foo work index && |
52 | # the third n is to get out in case it mistakenly does not apply | |
53 | test_write_lines n y n | git restore -p --source=$opt >output && | |
54 | verify_saved_state bar && | |
55 | verify_state dir/foo head index && | |
56 | test_grep "Discard" output | |
57 | ' | |
58 | done | |
4df3ec63 | 59 | |
7abc1869 | 60 | test_expect_success 'git restore -p --source=HEAD^' ' |
4df3ec63 NTND |
61 | set_state dir/foo work index && |
62 | # the third n is to get out in case it mistakenly does not apply | |
63 | test_write_lines n y n | git restore -p --source=HEAD^ && | |
64 | verify_saved_state bar && | |
65 | verify_state dir/foo parent index | |
66 | ' | |
67 | ||
7abc1869 | 68 | test_expect_success 'git restore -p --source=HEAD^...' ' |
5602b500 DL |
69 | set_state dir/foo work index && |
70 | # the third n is to get out in case it mistakenly does not apply | |
71 | test_write_lines n y n | git restore -p --source=HEAD^... && | |
72 | verify_saved_state bar && | |
73 | verify_state dir/foo parent index | |
74 | ' | |
75 | ||
7abc1869 | 76 | test_expect_success 'git restore -p handles deletion' ' |
4df3ec63 NTND |
77 | set_state dir/foo work index && |
78 | rm dir/foo && | |
79 | test_write_lines n y | git restore -p && | |
80 | verify_saved_state bar && | |
81 | verify_state dir/foo index index | |
82 | ' | |
83 | ||
84 | # The idea in the rest is that bar sorts first, so we always say 'y' | |
85 | # first and if the path limiter fails it'll apply to bar instead of | |
86 | # dir/foo. There's always an extra 'n' to reject edits to dir/foo in | |
87 | # the failure case (and thus get out of the loop). | |
88 | ||
7abc1869 | 89 | test_expect_success 'path limiting works: dir' ' |
4df3ec63 NTND |
90 | set_state dir/foo work head && |
91 | test_write_lines y n | git restore -p dir && | |
92 | verify_saved_state bar && | |
93 | verify_state dir/foo head head | |
94 | ' | |
95 | ||
7abc1869 | 96 | test_expect_success 'path limiting works: -- dir' ' |
4df3ec63 NTND |
97 | set_state dir/foo work head && |
98 | test_write_lines y n | git restore -p -- dir && | |
99 | verify_saved_state bar && | |
100 | verify_state dir/foo head head | |
101 | ' | |
102 | ||
7abc1869 | 103 | test_expect_success 'path limiting works: HEAD^ -- dir' ' |
4df3ec63 NTND |
104 | set_state dir/foo work head && |
105 | # the third n is to get out in case it mistakenly does not apply | |
106 | test_write_lines y n n | git restore -p --source=HEAD^ -- dir && | |
107 | verify_saved_state bar && | |
108 | verify_state dir/foo parent head | |
109 | ' | |
110 | ||
7abc1869 | 111 | test_expect_success 'path limiting works: foo inside dir' ' |
4df3ec63 NTND |
112 | set_state dir/foo work head && |
113 | # the third n is to get out in case it mistakenly does not apply | |
114 | test_write_lines y n n | (cd dir && git restore -p foo) && | |
115 | verify_saved_state bar && | |
116 | verify_state dir/foo head head | |
117 | ' | |
118 | ||
7abc1869 | 119 | test_expect_success 'none of this moved HEAD' ' |
4df3ec63 NTND |
120 | verify_saved_head |
121 | ' | |
122 | ||
123 | test_done |