path: root/archive.c
diff options
authorJeff King <>2013-03-11 01:32:32 (GMT)
committerJunio C Hamano <>2013-03-11 05:25:22 (GMT)
commitbd54cf17a4acfb9555b8a83b7e74fb0274c38bb4 (patch)
treed6e40cd0431e51757c4615d7ab3ef811f2058684 /archive.c
parentf838ce5826a2deffff7b70986fc7392d7114013e (diff)
archive: handle commits with an empty tree
git-archive relies on get_pathspec to convert its argv into a list of pathspecs. When get_pathspec is given an empty argv list, it returns a single pathspec, the empty string, to indicate that everything matches. When we feed this to our path_exists function, we typically see that the pathspec turns up at least one item in the tree, and we are happy. But when our tree is empty, we erroneously think it is because the pathspec is too limited, when in fact it is simply that there is nothing to be found in the tree. This is a weird corner case, but the correct behavior is almost certainly to produce an empty archive, not to exit with an error. This patch teaches git-archive to create empty archives when there is no pathspec given (we continue to complain if a pathspec is given, since it obviously is not matched). It also confirms that the tar and zip writers produce sane output in this instance. Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'archive.c')
1 files changed, 1 insertions, 1 deletions
diff --git a/archive.c b/archive.c
index 93e00bb..d254fa5 100644
--- a/archive.c
+++ b/archive.c
@@ -234,7 +234,7 @@ static void parse_pathspec_arg(const char **pathspec,
ar_args->pathspec = pathspec = get_pathspec("", pathspec);
if (pathspec) {
while (*pathspec) {
- if (!path_exists(ar_args->tree, *pathspec))
+ if (**pathspec && !path_exists(ar_args->tree, *pathspec))
die("path not found: %s", *pathspec);