Thread (6 messages) flat view 6 messages, 2 authors, 2016-06-15

Re: git archive and glob pathspecs

From: Duy Nguyen <hidden>
Date: 2016-06-15 23:02:25
Subsystem: the rest · Maintainer: Linus Torvalds

On Wed, Sep 3, 2014 at 5:17 AM, Peter Wu [off-list ref] wrote:
Hi,

The `git archive` seems to accept a pathspec judging from the error message (git
version 2.1.0):

    git archive HEAD -- :x
    fatal: pathspec 'x' did not match any files

When I try to use deeper glob specs however, it throws an error (this also
happens if I use `:(glob)**/Makefile`, tested in the git source tree):

    $ git archive HEAD -- ':(glob)*/Makefile'
    fatal: pathspec '*/Makefile' did not match any files

Strange enough, command `git log -- ':(glob)*/Makefile'` works. Any idea what is
wrong?
There may be something wrong. This patch seems to make it work for me,
but it includes lots of empty directories. I'll have a closer look
later (btw it's surprising that negative pathspec works too..)
diff --git a/archive.c b/archive.c
index 3fc0fb2..a5be58d 100644
--- a/archive.c
+++ b/archive.c
@@ -221,6 +221,7 @@ static int path_exists(struct tree *tree, const char *path)
  int ret;

  parse_pathspec(&pathspec, 0, 0, "", paths);
+ pathspec.recursive = 1;
  ret = read_tree_recursive(tree, "", 0, 0, &pathspec, reject_entry, NULL);
  free_pathspec(&pathspec);
  return ret != 0;
@@ -237,6 +238,7 @@ static void parse_pathspec_arg(const char **pathspec,
  parse_pathspec(&ar_args->pathspec, 0,
        PATHSPEC_PREFER_FULL,
        "", pathspec);
+ ar_args->pathspec.recursive = 1;
  if (pathspec) {
  while (*pathspec) {
  if (**pathspec && !path_exists(ar_args->tree, *pathspec))
-- 
Duy
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help