@@ -172,6 +172,50 @@ static struct patch_mode patch_mode_checkout_nothead = {
172
172
"the file\n" ),
173
173
};
174
174
175
+ static struct patch_mode patch_mode_worktree_head = {
176
+ .diff = { "diff-index" , NULL },
177
+ .apply = { "-R" , NULL },
178
+ .apply_check = { "-R" , NULL },
179
+ .is_reverse = 1 ,
180
+ .prompt_mode = {
181
+ N_ ("Discard mode change from index and worktree [y,n,q,a,d%s,?]? " ),
182
+ N_ ("Discard deletion from index and worktree [y,n,q,a,d%s,?]? " ),
183
+ N_ ("Discard this hunk from index and worktree [y,n,q,a,d%s,?]? " ),
184
+ },
185
+ .edit_hunk_hint = N_ ("If the patch applies cleanly, the edited hunk "
186
+ "will immediately be marked for discarding." ),
187
+ .help_patch_text =
188
+ N_ ("y - discard this hunk from worktree\n"
189
+ "n - do not discard this hunk from worktree\n"
190
+ "q - quit; do not discard this hunk or any of the remaining "
191
+ "ones\n"
192
+ "a - discard this hunk and all later hunks in the file\n"
193
+ "d - do not discard this hunk or any of the later hunks in "
194
+ "the file\n" ),
195
+ };
196
+
197
+ static struct patch_mode patch_mode_worktree_nothead = {
198
+ .diff = { "diff-index" , "-R" , NULL },
199
+ .apply = { NULL },
200
+ .apply_check = { NULL },
201
+ .is_reverse = 0 ,
202
+ .prompt_mode = {
203
+ N_ ("Apply mode change to index and worktree [y,n,q,a,d%s,?]? " ),
204
+ N_ ("Apply deletion to index and worktree [y,n,q,a,d%s,?]? " ),
205
+ N_ ("Apply this hunk to index and worktree [y,n,q,a,d%s,?]? " ),
206
+ },
207
+ .edit_hunk_hint = N_ ("If the patch applies cleanly, the edited hunk "
208
+ "will immediately be marked for applying." ),
209
+ .help_patch_text =
210
+ N_ ("y - apply this hunk to worktree\n"
211
+ "n - do not apply this hunk to worktree\n"
212
+ "q - quit; do not apply this hunk or any of the remaining "
213
+ "ones\n"
214
+ "a - apply this hunk and all later hunks in the file\n"
215
+ "d - do not apply this hunk or any of the later hunks in "
216
+ "the file\n" ),
217
+ };
218
+
175
219
struct hunk_header {
176
220
unsigned long old_offset , old_count , new_offset , new_count ;
177
221
/*
@@ -1510,6 +1554,13 @@ int run_add_p(struct repository *r, enum add_p_mode mode,
1510
1554
s .mode = & patch_mode_checkout_head ;
1511
1555
else
1512
1556
s .mode = & patch_mode_checkout_nothead ;
1557
+ } else if (mode == ADD_P_WORKTREE ) {
1558
+ if (!revision )
1559
+ s .mode = & patch_mode_checkout_index ;
1560
+ else if (!strcmp (revision , "HEAD" ))
1561
+ s .mode = & patch_mode_worktree_head ;
1562
+ else
1563
+ s .mode = & patch_mode_worktree_nothead ;
1513
1564
} else
1514
1565
s .mode = & patch_mode_stage ;
1515
1566
s .revision = revision ;
0 commit comments