@@ -3880,9 +3880,12 @@ void overlay_tree_on_index(struct index_state *istate,
38803880
38813881struct update_callback_data {
38823882 struct index_state * index ;
3883+ struct repository * repo ;
3884+ struct pathspec * pathspec ;
38833885 int include_sparse ;
38843886 int flags ;
38853887 int add_errors ;
3888+ int include_ignored_submodules ;
38863889};
38873890
38883891static int fix_unmerged_status (struct diff_filepair * p ,
@@ -3924,7 +3927,48 @@ static void update_callback(struct diff_queue_struct *q,
39243927 default :
39253928 die (_ ("unexpected diff status %c" ), p -> status );
39263929 case DIFF_STATUS_MODIFIED :
3927- case DIFF_STATUS_TYPE_CHANGED :
3930+ case DIFF_STATUS_TYPE_CHANGED : {
3931+ struct stat st ;
3932+ if (!lstat (path , & st ) && S_ISDIR (st .st_mode )) { // only consider submodule if it is a directory
3933+ const struct submodule * sub = submodule_from_path (data -> repo , null_oid (the_hash_algo ), path );
3934+ if (sub && sub -> name && sub -> ignore && !strcmp (sub -> ignore , "all" )) {
3935+ int pathspec_matches = 0 ;
3936+ char * norm_pathspec = NULL ;
3937+ int ps_i ;
3938+ trace_printf ("ignore=all %s\n" , path );
3939+ trace_printf ("pathspec %s\n" ,
3940+ (data -> pathspec && data -> pathspec -> nr ) ? "has pathspec" : "no pathspec" );
3941+ /* Safely scan all pathspec items (q->nr may exceed pathspec->nr). */
3942+ if (data -> pathspec ) {
3943+ for (ps_i = 0 ; ps_i < data -> pathspec -> nr ; ps_i ++ ) {
3944+ const char * m = data -> pathspec -> items [ps_i ].match ;
3945+ if (!m )
3946+ continue ;
3947+ norm_pathspec = xstrdup (m );
3948+ strip_dir_trailing_slashes (norm_pathspec );
3949+ if (!strcmp (path , norm_pathspec )) {
3950+ pathspec_matches = 1 ;
3951+ FREE_AND_NULL (norm_pathspec );
3952+ break ;
3953+ }
3954+ FREE_AND_NULL (norm_pathspec );
3955+ }
3956+ }
3957+ if (pathspec_matches ) {
3958+ if (data -> include_ignored_submodules && data -> include_ignored_submodules > 0 ) {
3959+ trace_printf ("Add ignored=all submodule due to --include_ignored_submodules: %s\n" , path );
3960+ } else {
3961+ printf (_ ("Skipping submodule due to ignore=all: %s" ), path );
3962+ printf (_ ("Use --include_ignored_submodules, if you really want to add them." ) );
3963+ continue ;
3964+ }
3965+ } else {
3966+ /* No explicit pathspec match -> skip silently (or with trace). */
3967+ trace_printf ("pathspec does not match %s\n" , path );
3968+ continue ;
3969+ }
3970+ }
3971+ }
39283972 if (add_file_to_index (data -> index , path , data -> flags )) {
39293973 if (!(data -> flags & ADD_CACHE_IGNORE_ERRORS ))
39303974 die (_ ("updating files failed" ));
@@ -3945,7 +3989,7 @@ static void update_callback(struct diff_queue_struct *q,
39453989
39463990int add_files_to_cache (struct repository * repo , const char * prefix ,
39473991 const struct pathspec * pathspec , char * ps_matched ,
3948- int include_sparse , int flags )
3992+ int include_sparse , int flags , int include_ignored_submodules )
39493993{
39503994 struct update_callback_data data ;
39513995 struct rev_info rev ;
@@ -3954,6 +3998,9 @@ int add_files_to_cache(struct repository *repo, const char *prefix,
39543998 data .index = repo -> index ;
39553999 data .include_sparse = include_sparse ;
39564000 data .flags = flags ;
4001+ data .repo = repo ;
4002+ data .include_ignored_submodules = include_ignored_submodules ;
4003+ data .pathspec = (struct pathspec * )pathspec ;
39574004
39584005 repo_init_revisions (repo , & rev , prefix );
39594006 setup_revisions (0 , NULL , & rev , NULL );
0 commit comments