@@ -46,6 +46,9 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
4646 struct cache_entry * ce = active_cache [i ];
4747 int err ;
4848
49+ if (ce_skip_worktree (ce ))
50+ continue ;
51+
4952 if (pathspec && !ce_path_match (& the_index , ce , pathspec , NULL ))
5053 continue ;
5154
@@ -146,6 +149,8 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)
146149 for (i = 0 ; i < active_nr ; i ++ ) {
147150 struct cache_entry * ce = active_cache [i ];
148151
152+ if (ce_skip_worktree (ce ))
153+ continue ;
149154 if (ce_stage (ce ))
150155 continue ; /* do not touch unmerged paths */
151156 if (!S_ISREG (ce -> ce_mode ) && !S_ISLNK (ce -> ce_mode ))
@@ -174,24 +179,44 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,
174179 * dst ++ = entry ;
175180 }
176181 dir -> nr = dst - dir -> entries ;
177- add_pathspec_matches_against_index (pathspec , & the_index , seen );
182+ add_pathspec_matches_against_index (pathspec , & the_index , seen ,
183+ PS_IGNORE_SKIP_WORKTREE );
178184 return seen ;
179185}
180186
181- static void refresh (int verbose , const struct pathspec * pathspec )
187+ static int refresh (int verbose , const struct pathspec * pathspec )
182188{
183189 char * seen ;
184- int i ;
190+ int i , ret = 0 ;
191+ char * skip_worktree_seen = NULL ;
192+ struct string_list only_match_skip_worktree = STRING_LIST_INIT_NODUP ;
193+ int flags = REFRESH_IGNORE_SKIP_WORKTREE |
194+ (verbose ? REFRESH_IN_PORCELAIN : REFRESH_QUIET );
185195
186196 seen = xcalloc (pathspec -> nr , 1 );
187- refresh_index (& the_index , verbose ? REFRESH_IN_PORCELAIN : REFRESH_QUIET ,
188- pathspec , seen , _ ("Unstaged changes after refreshing the index:" ));
197+ refresh_index (& the_index , flags , pathspec , seen ,
198+ _ ("Unstaged changes after refreshing the index:" ));
189199 for (i = 0 ; i < pathspec -> nr ; i ++ ) {
190- if (!seen [i ])
191- die (_ ("pathspec '%s' did not match any files" ),
192- pathspec -> items [i ].match );
200+ if (!seen [i ]) {
201+ if (matches_skip_worktree (pathspec , i , & skip_worktree_seen )) {
202+ string_list_append (& only_match_skip_worktree ,
203+ pathspec -> items [i ].original );
204+ } else {
205+ die (_ ("pathspec '%s' did not match any files" ),
206+ pathspec -> items [i ].original );
207+ }
208+ }
209+ }
210+
211+ if (only_match_skip_worktree .nr ) {
212+ advise_on_updating_sparse_paths (& only_match_skip_worktree );
213+ ret = 1 ;
193214 }
215+
194216 free (seen );
217+ free (skip_worktree_seen );
218+ string_list_clear (& only_match_skip_worktree , 0 );
219+ return ret ;
195220}
196221
197222int run_add_interactive (const char * revision , const char * patch_mode ,
@@ -567,15 +592,18 @@ int cmd_add(int argc, const char **argv, const char *prefix)
567592 }
568593
569594 if (refresh_only ) {
570- refresh (verbose , & pathspec );
595+ exit_status |= refresh (verbose , & pathspec );
571596 goto finish ;
572597 }
573598
574599 if (pathspec .nr ) {
575600 int i ;
601+ char * skip_worktree_seen = NULL ;
602+ struct string_list only_match_skip_worktree = STRING_LIST_INIT_NODUP ;
576603
577604 if (!seen )
578- seen = find_pathspecs_matching_against_index (& pathspec , & the_index );
605+ seen = find_pathspecs_matching_against_index (& pathspec ,
606+ & the_index , PS_IGNORE_SKIP_WORKTREE );
579607
580608 /*
581609 * file_exists() assumes exact match
@@ -589,12 +617,24 @@ int cmd_add(int argc, const char **argv, const char *prefix)
589617
590618 for (i = 0 ; i < pathspec .nr ; i ++ ) {
591619 const char * path = pathspec .items [i ].match ;
620+
592621 if (pathspec .items [i ].magic & PATHSPEC_EXCLUDE )
593622 continue ;
594- if (!seen [i ] && path [0 ] &&
595- ((pathspec .items [i ].magic &
596- (PATHSPEC_GLOB | PATHSPEC_ICASE )) ||
597- !file_exists (path ))) {
623+ if (seen [i ])
624+ continue ;
625+
626+ if (matches_skip_worktree (& pathspec , i , & skip_worktree_seen )) {
627+ string_list_append (& only_match_skip_worktree ,
628+ pathspec .items [i ].original );
629+ continue ;
630+ }
631+
632+ /* Don't complain at 'git add .' on empty repo */
633+ if (!path [0 ])
634+ continue ;
635+
636+ if ((pathspec .items [i ].magic & (PATHSPEC_GLOB | PATHSPEC_ICASE )) ||
637+ !file_exists (path )) {
598638 if (ignore_missing ) {
599639 int dtype = DT_UNKNOWN ;
600640 if (is_excluded (& dir , & the_index , path , & dtype ))
@@ -605,7 +645,16 @@ int cmd_add(int argc, const char **argv, const char *prefix)
605645 pathspec .items [i ].original );
606646 }
607647 }
648+
649+
650+ if (only_match_skip_worktree .nr ) {
651+ advise_on_updating_sparse_paths (& only_match_skip_worktree );
652+ exit_status = 1 ;
653+ }
654+
608655 free (seen );
656+ free (skip_worktree_seen );
657+ string_list_clear (& only_match_skip_worktree , 0 );
609658 }
610659
611660 plug_bulk_checkin ();
0 commit comments