@@ -116,32 +116,42 @@ static void update_index_from_diff(struct diff_queue_struct *q,
116
116
struct diff_options * opt , void * data )
117
117
{
118
118
int i ;
119
+ int intent_to_add = * (int * )data ;
119
120
120
121
for (i = 0 ; i < q -> nr ; i ++ ) {
121
122
struct diff_filespec * one = q -> queue [i ]-> one ;
122
- if (one -> mode && !is_null_sha1 (one -> sha1 )) {
123
- struct cache_entry * ce ;
124
- ce = make_cache_entry (one -> mode , one -> sha1 , one -> path ,
125
- 0 , 0 );
126
- if (!ce )
127
- die (_ ("make_cache_entry failed for path '%s'" ),
128
- one -> path );
129
- add_cache_entry (ce , ADD_CACHE_OK_TO_ADD |
130
- ADD_CACHE_OK_TO_REPLACE );
131
- } else
123
+ int is_missing = !(one -> mode && !is_null_sha1 (one -> sha1 ));
124
+ struct cache_entry * ce ;
125
+
126
+ if (is_missing && !intent_to_add ) {
132
127
remove_file_from_cache (one -> path );
128
+ continue ;
129
+ }
130
+
131
+ ce = make_cache_entry (one -> mode , one -> sha1 , one -> path ,
132
+ 0 , 0 );
133
+ if (!ce )
134
+ die (_ ("make_cache_entry failed for path '%s'" ),
135
+ one -> path );
136
+ if (is_missing ) {
137
+ ce -> ce_flags |= CE_INTENT_TO_ADD ;
138
+ set_object_name_for_intent_to_add_entry (ce );
139
+ }
140
+ add_cache_entry (ce , ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE );
133
141
}
134
142
}
135
143
136
144
static int read_from_tree (const struct pathspec * pathspec ,
137
- unsigned char * tree_sha1 )
145
+ unsigned char * tree_sha1 ,
146
+ int intent_to_add )
138
147
{
139
148
struct diff_options opt ;
140
149
141
150
memset (& opt , 0 , sizeof (opt ));
142
151
copy_pathspec (& opt .pathspec , pathspec );
143
152
opt .output_format = DIFF_FORMAT_CALLBACK ;
144
153
opt .format_callback = update_index_from_diff ;
154
+ opt .format_callback_data = & intent_to_add ;
145
155
146
156
if (do_diff_cache (tree_sha1 , & opt ))
147
157
return 1 ;
@@ -258,6 +268,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
258
268
const char * rev ;
259
269
unsigned char sha1 [20 ];
260
270
struct pathspec pathspec ;
271
+ int intent_to_add = 0 ;
261
272
const struct option options [] = {
262
273
OPT__QUIET (& quiet , N_ ("be quiet, only report errors" )),
263
274
OPT_SET_INT (0 , "mixed" , & reset_type ,
@@ -270,6 +281,8 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
270
281
OPT_SET_INT (0 , "keep" , & reset_type ,
271
282
N_ ("reset HEAD but keep local changes" ), KEEP ),
272
283
OPT_BOOL ('p' , "patch" , & patch_mode , N_ ("select hunks interactively" )),
284
+ OPT_BOOL ('N' , "intent-to-add" , & intent_to_add ,
285
+ N_ ("record only the fact that removed paths will be added later" )),
273
286
OPT_END ()
274
287
};
275
288
@@ -327,6 +340,9 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
327
340
die (_ ("%s reset is not allowed in a bare repository" ),
328
341
_ (reset_type_names [reset_type ]));
329
342
343
+ if (intent_to_add && reset_type != MIXED )
344
+ die (_ ("-N can only be used with --mixed" ));
345
+
330
346
/* Soft reset does not touch the index file nor the working tree
331
347
* at all, but requires them in a good order. Other resets reset
332
348
* the index file to the tree object we are switching to. */
@@ -338,7 +354,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
338
354
int newfd = hold_locked_index (lock , 1 );
339
355
if (reset_type == MIXED ) {
340
356
int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN ;
341
- if (read_from_tree (& pathspec , sha1 ))
357
+ if (read_from_tree (& pathspec , sha1 , intent_to_add ))
342
358
return 1 ;
343
359
refresh_index (& the_index , flags , NULL , NULL ,
344
360
_ ("Unstaged changes after reset:" ));
0 commit comments