Skip to content

Commit c6eba1d

Browse files
committed
Merge branch 'rs/maint-archive-match-pathspec' into maint
* rs/maint-archive-match-pathspec: archive: complain about path specs that don't match anything
2 parents 8ff8830 + d5f53d6 commit c6eba1d

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

archive.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,33 @@ static const struct archiver *lookup_archiver(const char *name)
211211
return NULL;
212212
}
213213

214+
static int reject_entry(const unsigned char *sha1, const char *base,
215+
int baselen, const char *filename, unsigned mode,
216+
int stage, void *context)
217+
{
218+
return -1;
219+
}
220+
221+
static int path_exists(struct tree *tree, const char *path)
222+
{
223+
const char *pathspec[] = { path, NULL };
224+
225+
if (read_tree_recursive(tree, "", 0, 0, pathspec, reject_entry, NULL))
226+
return 1;
227+
return 0;
228+
}
229+
214230
static void parse_pathspec_arg(const char **pathspec,
215231
struct archiver_args *ar_args)
216232
{
217-
ar_args->pathspec = get_pathspec("", pathspec);
233+
ar_args->pathspec = pathspec = get_pathspec("", pathspec);
234+
if (pathspec) {
235+
while (*pathspec) {
236+
if (!path_exists(ar_args->tree, *pathspec))
237+
die("path not found: %s", *pathspec);
238+
pathspec++;
239+
}
240+
}
218241
}
219242

220243
static void parse_treeish_arg(const char **argv,

0 commit comments

Comments
 (0)