{"thread":{"id":"62158","subject":"Archive from bare repo?","startedAt":"2024-09-20T17:48:43Z","lastAt":"2024-09-21T22:02:34Z","messageCount":4,"participants":["Ronan Pigott","René Scharfe"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"503149","messageId":"4ace58897feee2d86839af1a36770e49810e59b8@rjp.ie","threadId":"62158","inReplyTo":null,"subject":"Archive from bare repo?","fromName":"Ronan Pigott","fromEmail":"ronan@rjp.ie","sentAt":"2024-09-20T17:48:39Z","receivedAt":"2024-09-20T17:48:43Z","isPatch":false,"sender":{"key":"ronan@rjp.ie","avatar":"https://avatars.githubusercontent.com/u/12577529?v=4"},"body":"Hi git,\n\nI'm trying and failing to create a specific archive from a bare repo. The\nfollowing all works correctly:\n\n  $ git clone https://my.git.repo/test --bare test\n  $ git --git-dir=test archive @ | tar -tf - # archive of full repo\n  $ git --git-dir=test cat-file -p @:.gitattributes # shows subset of files with myattr set\n  $ git --work-tree=/var/empty --git-dir=test reset --mixed\n  $ git --work-tree=/var/empty --git-dir=test ls-files ':(attr:myattr)' # list of files with myattr set\n\nNow I get:\n\n  $ git --git-dir=test archive @ ':(attr:login)'\n  fatal: pathspec ':(attr:login)' did not match any files\n\nThe manpage indicates that git-archive should use the .gitattributes from the\narchived tree, and as indicated above it has the expected content. Why doesn't\nthis produce an archive with the files listed by ls-files from above? Is there\na way to achive the archive I want?\n\nThanks,\nRonan\n"},{"id":"503150","messageId":"23220a9ab261d3d8d09586cce3964e6772f531a6@rjp.ie","threadId":"62158","inReplyTo":"4ace58897feee2d86839af1a36770e49810e59b8@rjp.ie","subject":"Re: Archive from bare repo?","fromName":"Ronan Pigott","fromEmail":"ronan@rjp.ie","sentAt":"2024-09-20T17:53:28Z","receivedAt":"2024-09-20T17:53:31Z","isPatch":false,"sender":{"key":"ronan@rjp.ie","avatar":"https://avatars.githubusercontent.com/u/12577529?v=4"},"body":"September 20, 2024 at 10:48 AM, \"Ronan Pigott\" <ronan@rjp.ie> wrote:\n\n>  $ git --work-tree=/var/empty --git-dir=test ls-files ':(attr:myattr)' # list of files with myattr set\n \n>  $ git --git-dir=test archive @ ':(attr:login)'\n> \n>  fatal: pathspec ':(attr:login)' did not match any files\n\nSorry for the typo, both cases are using the same pathspec\n':(attr:login)' but the issue as described remains.\n"},{"id":"503205","messageId":"66c3e9fa-ecfe-4af2-a970-c1afdbc2b7f2@web.de","threadId":"62158","inReplyTo":"4ace58897feee2d86839af1a36770e49810e59b8@rjp.ie","subject":"[PATCH] archive: load index before pathspec checks","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2024-09-21T20:23:39Z","receivedAt":"2024-09-21T20:23:47Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"git archive checks whether pathspec arguments match anything to avoid\nsurprises due to typos and later loads the index to get attributes.\n\nThis order was OK when these features were introduced by ba053ea96c\n(archive: do not read .gitattributes in working directory, 2009-04-18)\nand d5f53d6d6f (archive: complain about path specs that don't match\nanything, 2009-12-12).\n\nBut when attribute matching was added to pathspec in b0db704652\n(pathspec: allow querying for attributes, 2017-03-13), the pathspec\nchecker in git archive did not support it fully, because it lacks the\nattributes from the index.\n\nLoad the index earlier, before the pathspec check, to support attr\npathspecs.\n\nReported-by: Ronan Pigott <ronan@rjp.ie>\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n archive.c           | 39 ++++++++++++++++++++-------------------\n t/t5000-tar-tree.sh | 12 ++++++++++++\n 2 files changed, 32 insertions(+), 19 deletions(-)\n\ndiff --git a/archive.c b/archive.c\nindex 9ba96aae4f..58f86bf75c 100644\n--- a/archive.c\n+++ b/archive.c\n@@ -304,8 +304,6 @@ int write_archive_entries(struct archiver_args *args,\n \t\twrite_archive_entry_fn_t write_entry)\n {\n \tstruct archiver_context context;\n-\tstruct unpack_trees_options opts;\n-\tstruct tree_desc t;\n \tint err;\n \tstruct strbuf path_in_archive = STRBUF_INIT;\n \tstruct strbuf content = STRBUF_INIT;\n@@ -331,23 +329,6 @@ int write_archive_entries(struct archiver_args *args,\n \tcontext.args = args;\n \tcontext.write_entry = write_entry;\n\n-\t/*\n-\t * Setup index and instruct attr to read index only\n-\t */\n-\tif (!args->worktree_attributes) {\n-\t\tmemset(&opts, 0, sizeof(opts));\n-\t\topts.index_only = 1;\n-\t\topts.head_idx = -1;\n-\t\topts.src_index = args->repo->index;\n-\t\topts.dst_index = args->repo->index;\n-\t\topts.fn = oneway_merge;\n-\t\tinit_tree_desc(&t, &args->tree->object.oid,\n-\t\t\t       args->tree->buffer, args->tree->size);\n-\t\tif (unpack_trees(1, &t, &opts))\n-\t\t\treturn -1;\n-\t\tgit_attr_set_direction(GIT_ATTR_INDEX);\n-\t}\n-\n \terr = read_tree(args->repo, args->tree,\n \t\t\t&args->pathspec,\n \t\t\tqueue_or_write_archive_entry,\n@@ -540,6 +521,26 @@ static void parse_treeish_arg(const char **argv,\n \tif (!tree)\n \t\tdie(_(\"not a tree object: %s\"), oid_to_hex(&oid));\n\n+\t/*\n+\t * Setup index and instruct attr to read index only\n+\t */\n+\tif (!ar_args->worktree_attributes) {\n+\t\tstruct unpack_trees_options opts;\n+\t\tstruct tree_desc t;\n+\n+\t\tmemset(&opts, 0, sizeof(opts));\n+\t\topts.index_only = 1;\n+\t\topts.head_idx = -1;\n+\t\topts.src_index = ar_args->repo->index;\n+\t\topts.dst_index = ar_args->repo->index;\n+\t\topts.fn = oneway_merge;\n+\t\tinit_tree_desc(&t, &tree->object.oid, tree->buffer, tree->size);\n+\t\tif (unpack_trees(1, &t, &opts))\n+\t\t\tdie(_(\"unable to checkout working tree\"));\n+\n+\t\tgit_attr_set_direction(GIT_ATTR_INDEX);\n+\t}\n+\n \tar_args->refname = ref;\n \tar_args->tree = tree;\n \tar_args->commit_oid = commit_oid;\ndiff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh\nindex 7abba8a4b2..b9fda973f7 100755\n--- a/t/t5000-tar-tree.sh\n+++ b/t/t5000-tar-tree.sh\n@@ -137,6 +137,8 @@ test_expect_success 'end-of-options is correctly eaten' '\n\n test_expect_success 'populate workdir' '\n \tmkdir a &&\n+\techo \"a files_named_a\" >.gitattributes &&\n+\tgit add .gitattributes &&\n \techo simple textfile >a/a &&\n \tten=0123456789 &&\n \thundred=\"$ten$ten$ten$ten$ten$ten$ten$ten$ten$ten\" &&\n@@ -450,6 +452,16 @@ test_expect_success 'allow pathspecs that resolve to the current directory' '\n \ttest_cmp expect actual\n '\n\n+test_expect_success 'attr pathspec in bare repo' '\n+\ttest_expect_code 0 git --git-dir=bare.git archive -v HEAD \\\n+\t\t\":(attr:files_named_a)\" >/dev/null 2>actual &&\n+\tcat >expect <<-\\EOF &&\n+\ta/\n+\ta/a\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n # Pull the size and date of each entry in a tarfile using the system tar.\n #\n # We'll pull out only the year from the date; that avoids any question of\n--\n2.46.0\n"},{"id":"503207","messageId":"fa8c473f-8941-4749-8561-3444ce7ce113@web.de","threadId":"62158","inReplyTo":"f8e0ad836366480e32ec5b40b753cb533dd41cb6@rjp.ie","subject":"Re: [PATCH] archive: load index before pathspec checks","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2024-09-21T22:02:30Z","receivedAt":"2024-09-21T22:02:34Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Hello Ronan,\n\nAm 21.09.24 um 23:23 schrieb Ronan Pigott:\n> Thanks for the patch. I tried it applied to 2.46.1 and it works as expected.\n\nthank you for testing, and for the original report!\n\nRené\n\n"}]}