@@ -117,7 +117,19 @@ static void fill_pathspec_matches(const char **pathspec, char *seen, int specs)
117
117
}
118
118
}
119
119
120
- static void prune_directory (struct dir_struct * dir , const char * * pathspec , int prefix )
120
+ static char * find_used_pathspec (const char * * pathspec )
121
+ {
122
+ char * seen ;
123
+ int i ;
124
+
125
+ for (i = 0 ; pathspec [i ]; i ++ )
126
+ ; /* just counting */
127
+ seen = xcalloc (i , 1 );
128
+ fill_pathspec_matches (pathspec , seen , i );
129
+ return seen ;
130
+ }
131
+
132
+ static char * prune_directory (struct dir_struct * dir , const char * * pathspec , int prefix )
121
133
{
122
134
char * seen ;
123
135
int i , specs ;
@@ -137,13 +149,7 @@ static void prune_directory(struct dir_struct *dir, const char **pathspec, int p
137
149
}
138
150
dir -> nr = dst - dir -> entries ;
139
151
fill_pathspec_matches (pathspec , seen , specs );
140
-
141
- for (i = 0 ; i < specs ; i ++ ) {
142
- if (!seen [i ] && pathspec [i ][0 ] && !file_exists (pathspec [i ]))
143
- die ("pathspec '%s' did not match any files" ,
144
- pathspec [i ]);
145
- }
146
- free (seen );
152
+ return seen ;
147
153
}
148
154
149
155
static void treat_gitlinks (const char * * pathspec )
@@ -359,6 +365,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
359
365
int flags ;
360
366
int add_new_files ;
361
367
int require_pathspec ;
368
+ char * seen = NULL ;
362
369
363
370
git_config (add_config , NULL );
364
371
@@ -418,14 +425,27 @@ int cmd_add(int argc, const char **argv, const char *prefix)
418
425
/* This picks up the paths that are not tracked */
419
426
baselen = fill_directory (& dir , pathspec );
420
427
if (pathspec )
421
- prune_directory (& dir , pathspec , baselen );
428
+ seen = prune_directory (& dir , pathspec , baselen );
422
429
}
423
430
424
431
if (refresh_only ) {
425
432
refresh (verbose , pathspec );
426
433
goto finish ;
427
434
}
428
435
436
+ if (pathspec ) {
437
+ int i ;
438
+ if (!seen )
439
+ seen = find_used_pathspec (pathspec );
440
+ for (i = 0 ; pathspec [i ]; i ++ ) {
441
+ if (!seen [i ] && pathspec [i ][0 ]
442
+ && !file_exists (pathspec [i ]))
443
+ die ("pathspec '%s' did not match any files" ,
444
+ pathspec [i ]);
445
+ }
446
+ free (seen );
447
+ }
448
+
429
449
exit_status |= add_files_to_cache (prefix , pathspec , flags );
430
450
431
451
if (add_new_files )
0 commit comments