@@ -141,6 +141,8 @@ int check_apply_state(struct apply_state *state, int force_apply)
141
141
return error (_ ("--cached outside a repository" ));
142
142
state -> check_index = 1 ;
143
143
}
144
+ if (state -> ita_only && (state -> check_index || is_not_gitdir ))
145
+ state -> ita_only = 0 ;
144
146
if (state -> check_index )
145
147
state -> unsafe_paths = 0 ;
146
148
@@ -4242,7 +4244,7 @@ static void patch_stats(struct apply_state *state, struct patch *patch)
4242
4244
4243
4245
static int remove_file (struct apply_state * state , struct patch * patch , int rmdir_empty )
4244
4246
{
4245
- if (state -> update_index ) {
4247
+ if (state -> update_index && ! state -> ita_only ) {
4246
4248
if (remove_file_from_cache (patch -> old_name ) < 0 )
4247
4249
return error (_ ("unable to remove %s from index" ), patch -> old_name );
4248
4250
}
@@ -4265,15 +4267,15 @@ static int add_index_file(struct apply_state *state,
4265
4267
int namelen = strlen (path );
4266
4268
unsigned ce_size = cache_entry_size (namelen );
4267
4269
4268
- if (!state -> update_index )
4269
- return 0 ;
4270
-
4271
4270
ce = xcalloc (1 , ce_size );
4272
4271
memcpy (ce -> name , path , namelen );
4273
4272
ce -> ce_mode = create_ce_mode (mode );
4274
4273
ce -> ce_flags = create_ce_flags (0 );
4275
4274
ce -> ce_namelen = namelen ;
4276
- if (S_ISGITLINK (mode )) {
4275
+ if (state -> ita_only ) {
4276
+ ce -> ce_flags |= CE_INTENT_TO_ADD ;
4277
+ set_object_name_for_intent_to_add_entry (ce );
4278
+ } else if (S_ISGITLINK (mode )) {
4277
4279
const char * s ;
4278
4280
4279
4281
if (!skip_prefix (buf , "Subproject commit " , & s ) ||
@@ -4465,8 +4467,9 @@ static int create_file(struct apply_state *state, struct patch *patch)
4465
4467
4466
4468
if (patch -> conflicted_threeway )
4467
4469
return add_conflicted_stages_file (state , patch );
4468
- else
4470
+ else if ( state -> update_index )
4469
4471
return add_index_file (state , path , mode , buf , size );
4472
+ return 0 ;
4470
4473
}
4471
4474
4472
4475
/* phase zero is to remove, phase one is to create */
@@ -4686,7 +4689,7 @@ static int apply_patch(struct apply_state *state,
4686
4689
if (state -> whitespace_error && (state -> ws_error_action == die_on_ws_error ))
4687
4690
state -> apply = 0 ;
4688
4691
4689
- state -> update_index = state -> check_index && state -> apply ;
4692
+ state -> update_index = ( state -> check_index || state -> ita_only ) && state -> apply ;
4690
4693
if (state -> update_index && !is_lock_file_locked (& state -> lock_file )) {
4691
4694
if (state -> index_file )
4692
4695
hold_lock_file_for_update (& state -> lock_file ,
@@ -4941,6 +4944,8 @@ int apply_parse_options(int argc, const char **argv,
4941
4944
N_ ("instead of applying the patch, see if the patch is applicable" )),
4942
4945
OPT_BOOL (0 , "index" , & state -> check_index ,
4943
4946
N_ ("make sure the patch is applicable to the current index" )),
4947
+ OPT_BOOL ('N' , "intent-to-add" , & state -> ita_only ,
4948
+ N_ ("mark new files with `git add --intent-to-add`" )),
4944
4949
OPT_BOOL (0 , "cached" , & state -> cached ,
4945
4950
N_ ("apply a patch without touching the working tree" )),
4946
4951
OPT_BOOL_F (0 , "unsafe-paths" , & state -> unsafe_paths ,
0 commit comments