@@ -40,6 +40,72 @@ static struct patch_mode patch_mode_stage = {
40
40
"the file\n" )
41
41
};
42
42
43
+ static struct patch_mode patch_mode_stash = {
44
+ .diff = { "diff-index" , "HEAD" , NULL },
45
+ .apply = { "--cached" , NULL },
46
+ .apply_check = { "--cached" , NULL },
47
+ .is_reverse = 0 ,
48
+ .prompt_mode = {
49
+ N_ ("Stash mode change [y,n,q,a,d%s,?]? " ),
50
+ N_ ("Stash deletion [y,n,q,a,d%s,?]? " ),
51
+ N_ ("Stash this hunk [y,n,q,a,d%s,?]? " ),
52
+ },
53
+ .edit_hunk_hint = N_ ("If the patch applies cleanly, the edited hunk "
54
+ "will immediately be marked for stashing." ),
55
+ .help_patch_text =
56
+ N_ ("y - stash this hunk\n"
57
+ "n - do not stash this hunk\n"
58
+ "q - quit; do not stash this hunk or any of the remaining "
59
+ "ones\n"
60
+ "a - stash this hunk and all later hunks in the file\n"
61
+ "d - do not stash this hunk or any of the later hunks in "
62
+ "the file\n" ),
63
+ };
64
+
65
+ static struct patch_mode patch_mode_reset_head = {
66
+ .diff = { "diff-index" , "--cached" , NULL },
67
+ .apply = { "-R" , "--cached" , NULL },
68
+ .apply_check = { "-R" , "--cached" , NULL },
69
+ .is_reverse = 1 ,
70
+ .prompt_mode = {
71
+ N_ ("Unstage mode change [y,n,q,a,d%s,?]? " ),
72
+ N_ ("Unstage deletion [y,n,q,a,d%s,?]? " ),
73
+ N_ ("Unstage this hunk [y,n,q,a,d%s,?]? " ),
74
+ },
75
+ .edit_hunk_hint = N_ ("If the patch applies cleanly, the edited hunk "
76
+ "will immediately be marked for unstaging." ),
77
+ .help_patch_text =
78
+ N_ ("y - unstage this hunk\n"
79
+ "n - do not unstage this hunk\n"
80
+ "q - quit; do not unstage this hunk or any of the remaining "
81
+ "ones\n"
82
+ "a - unstage this hunk and all later hunks in the file\n"
83
+ "d - do not unstage this hunk or any of the later hunks in "
84
+ "the file\n" ),
85
+ };
86
+
87
+ static struct patch_mode patch_mode_reset_nothead = {
88
+ .diff = { "diff-index" , "-R" , "--cached" , NULL },
89
+ .apply = { "--cached" , NULL },
90
+ .apply_check = { "--cached" , NULL },
91
+ .is_reverse = 0 ,
92
+ .prompt_mode = {
93
+ N_ ("Apply mode change to index [y,n,q,a,d%s,?]? " ),
94
+ N_ ("Apply deletion to index [y,n,q,a,d%s,?]? " ),
95
+ N_ ("Apply this hunk to index [y,n,q,a,d%s,?]? " ),
96
+ },
97
+ .edit_hunk_hint = N_ ("If the patch applies cleanly, the edited hunk "
98
+ "will immediately be marked for applying." ),
99
+ .help_patch_text =
100
+ N_ ("y - apply this hunk to index\n"
101
+ "n - do not apply this hunk to index\n"
102
+ "q - quit; do not apply this hunk or any of the remaining "
103
+ "ones\n"
104
+ "a - apply this hunk and all later hunks in the file\n"
105
+ "d - do not apply this hunk or any of the later hunks in "
106
+ "the file\n" ),
107
+ };
108
+
43
109
struct hunk_header {
44
110
unsigned long old_offset , old_count , new_offset , new_count ;
45
111
/*
@@ -1284,7 +1350,15 @@ int run_add_p(struct repository *r, enum add_p_mode mode,
1284
1350
if (init_add_i_state (r , & s .s ))
1285
1351
return error ("Could not read `add -i` config" );
1286
1352
1287
- s .mode = & patch_mode_stage ;
1353
+ if (mode == ADD_P_STASH )
1354
+ s .mode = & patch_mode_stash ;
1355
+ else if (mode == ADD_P_RESET ) {
1356
+ if (!revision || !strcmp (revision , "HEAD" ))
1357
+ s .mode = & patch_mode_reset_head ;
1358
+ else
1359
+ s .mode = & patch_mode_reset_nothead ;
1360
+ } else
1361
+ s .mode = & patch_mode_stage ;
1288
1362
s .revision = revision ;
1289
1363
1290
1364
if (repo_refresh_and_write_index (r , REFRESH_QUIET , 0 ) < 0 ||
0 commit comments