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