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