@@ -41,7 +41,19 @@ static void fill_pathspec_matches(const char **pathspec, char *seen, int specs)
41
41
}
42
42
}
43
43
44
- static void prune_directory (struct dir_struct * dir , const char * * pathspec , int prefix )
44
+ static char * find_used_pathspec (const char * * pathspec )
45
+ {
46
+ char * seen ;
47
+ int i ;
48
+
49
+ for (i = 0 ; pathspec [i ]; i ++ )
50
+ ; /* just counting */
51
+ seen = xcalloc (i , 1 );
52
+ fill_pathspec_matches (pathspec , seen , i );
53
+ return seen ;
54
+ }
55
+
56
+ static char * prune_directory (struct dir_struct * dir , const char * * pathspec , int prefix )
45
57
{
46
58
char * seen ;
47
59
int i , specs ;
@@ -61,13 +73,7 @@ static void prune_directory(struct dir_struct *dir, const char **pathspec, int p
61
73
}
62
74
dir -> nr = dst - dir -> entries ;
63
75
fill_pathspec_matches (pathspec , seen , specs );
64
-
65
- for (i = 0 ; i < specs ; i ++ ) {
66
- if (!seen [i ] && pathspec [i ][0 ] && !file_exists (pathspec [i ]))
67
- die ("pathspec '%s' did not match any files" ,
68
- pathspec [i ]);
69
- }
70
- free (seen );
76
+ return seen ;
71
77
}
72
78
73
79
static void treat_gitlinks (const char * * pathspec )
@@ -283,6 +289,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
283
289
int flags ;
284
290
int add_new_files ;
285
291
int require_pathspec ;
292
+ char * seen = NULL ;
286
293
287
294
git_config (add_config , NULL );
288
295
@@ -342,14 +349,27 @@ int cmd_add(int argc, const char **argv, const char *prefix)
342
349
/* This picks up the paths that are not tracked */
343
350
baselen = fill_directory (& dir , pathspec );
344
351
if (pathspec )
345
- prune_directory (& dir , pathspec , baselen );
352
+ seen = prune_directory (& dir , pathspec , baselen );
346
353
}
347
354
348
355
if (refresh_only ) {
349
356
refresh (verbose , pathspec );
350
357
goto finish ;
351
358
}
352
359
360
+ if (pathspec ) {
361
+ int i ;
362
+ if (!seen )
363
+ seen = find_used_pathspec (pathspec );
364
+ for (i = 0 ; pathspec [i ]; i ++ ) {
365
+ if (!seen [i ] && pathspec [i ][0 ]
366
+ && !file_exists (pathspec [i ]))
367
+ die ("pathspec '%s' did not match any files" ,
368
+ pathspec [i ]);
369
+ }
370
+ free (seen );
371
+ }
372
+
353
373
exit_status |= add_files_to_cache (prefix , pathspec , flags );
354
374
355
375
if (add_new_files )
0 commit comments