178
}
179
dir->nr = dst - dir->entries;
180
add_pathspec_matches_against_index(pathspec, &the_index, seen,
181
- PS_HEED_SKIP_WORKTREE);
181
+ PS_IGNORE_SKIP_WORKTREE);
182
return seen;
183
}
184
185
-static void refresh(int verbose, const struct pathspec *pathspec)
185
+static int refresh(int verbose, const struct pathspec *pathspec)
186
{
187
char *seen;
188
- int i;
188
+ int i, ret = 0;
189
+ char *skip_worktree_seen = NULL;
190
+ struct string_list only_match_skip_worktree = STRING_LIST_INIT_NODUP;
191
+ int flags = REFRESH_IGNORE_SKIP_WORKTREE |
192
+ (verbose ? REFRESH_IN_PORCELAIN : REFRESH_QUIET);
193
194
seen = xcalloc(pathspec->nr, 1);
191
- refresh_index(&the_index, verbose ? REFRESH_IN_PORCELAIN : REFRESH_QUIET,
192
- pathspec, seen, _("Unstaged changes after refreshing the index:"));
195
+ refresh_index(&the_index, flags, pathspec, seen,
196
+ _("Unstaged changes after refreshing the index:"));
197
for (i = 0; i < pathspec->nr; i++) {
194
- if (!seen[i])
195
- die(_("pathspec '%s' did not match any files"),
196
- pathspec->items[i].original);
198
+ if (!seen[i]) {
199
+ if (matches_skip_worktree(pathspec, i, &skip_worktree_seen)) {
200
+ string_list_append(&only_match_skip_worktree,
201
+ pathspec->items[i].original);
202
+ } else {
203
+ die(_("pathspec '%s' did not match any files"),
204
+ pathspec->items[i].original);
205
+ }
206
+ }
207
+ }
208
+
209
+ if (only_match_skip_worktree.nr) {
210
+ advise_on_updating_sparse_paths(&only_match_skip_worktree);
211
+ ret = 1;
212
}
213
+
214
free(seen);
215
+ free(skip_worktree_seen);
216
+ string_list_clear(&only_match_skip_worktree, 0);
217
+ return ret;
218
}
219
220
int run_add_interactive(const char *revision, const char *patch_mode,
590
}
591
592
if (refresh_only) {
574
- refresh(verbose, &pathspec);
593
+ exit_status |= refresh(verbose, &pathspec);
594
goto finish;
595
}
596
597
if (pathspec.nr) {
598
int i;
599
+ char *skip_worktree_seen = NULL;
600
+ struct string_list only_match_skip_worktree = STRING_LIST_INIT_NODUP;
601
602
if (!seen)
603
seen = find_pathspecs_matching_against_index(&pathspec,
583
- &the_index, PS_HEED_SKIP_WORKTREE);
604
+ &the_index, PS_IGNORE_SKIP_WORKTREE);
605
606
/*
607
* file_exists() assumes exact match
615
616
for (i = 0; i < pathspec.nr; i++) {
617
const char *path = pathspec.items[i].match;
618
+
619
if (pathspec.items[i].magic & PATHSPEC_EXCLUDE)
620
continue;
599
- if (!seen[i] && path[0] &&
600
- ((pathspec.items[i].magic &
601
- (PATHSPEC_GLOB | PATHSPEC_ICASE)) ||
602
- !file_exists(path))) {
621
+ if (seen[i])
622
+ continue;
623
+
624
+ if (matches_skip_worktree(&pathspec, i, &skip_worktree_seen)) {
625
+ string_list_append(&only_match_skip_worktree,
626
+ pathspec.items[i].original);
627
+ continue;
628
+ }
629
+
630
+ /* Don't complain at 'git add .' on empty repo */
631
+ if (!path[0])
632
+ continue;
633
+
634
+ if ((pathspec.items[i].magic & (PATHSPEC_GLOB | PATHSPEC_ICASE)) ||
635
+ !file_exists(path)) {
636
if (ignore_missing) {
637
int dtype = DT_UNKNOWN;
638
if (is_excluded(&dir, &the_index, path, &dtype))
643
pathspec.items[i].original);
644
}
645
}
646
+
647
+
648
+ if (only_match_skip_worktree.nr) {
649
+ advise_on_updating_sparse_paths(&only_match_skip_worktree);
650
+ exit_status = 1;
651
+ }
652
+
653
free(seen);
654
+ free(skip_worktree_seen);
655
+ string_list_clear(&only_match_skip_worktree, 0);
656
}
657
658
plug_bulk_checkin();