{"thread":{"id":"13849","subject":"git-archive and unwanted .gitattributes","startedAt":"2008-06-07T15:21:48Z","lastAt":"2008-06-09T04:24:19Z","messageCount":8,"participants":["Nguyen Thai Ngoc Duy","Jakub Narebski","René Scharfe","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"79047","messageId":"fcaeb9bf0806070821r5ba650c2x1fef7947fc4a2de5@mail.gmail.com","threadId":"13849","inReplyTo":null,"subject":"git-archive and unwanted .gitattributes","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2008-06-07T15:21:48Z","receivedAt":"2008-06-07T15:21:48Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Hi,\n\nCurrently attr.c will read .gitattributes on disk no matter there is a\nreal worktree or not. This can lead to strange behavior. For example\nwhen I do\n\nmkdir a && cd a\ngit init\necho '$Format:%s$' > a\ngit add a && git commit -m initial\ncd ..\necho 'a export-subst' > .gitattributes # let's assume this is an accident.\ngit --git-dir=a/.git archive --format=tar HEAD|tar xO a\n\nI expect it to show '$Format:%s$', not \"initial\". git-archive should\nnot bother reading that .gitattributes. I thought an\nis_inside_work_tree() check would be enough. Unfortunately, setting\n--git-dir will automatically set worktree too. Any ideas?\n-- \nDuy\n"},{"id":"79049","messageId":"m33anpxn63.fsf@localhost.localdomain","threadId":"13849","inReplyTo":"fcaeb9bf0806070821r5ba650c2x1fef7947fc4a2de5@mail.gmail.com","subject":"Re: git-archive and unwanted .gitattributes","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-06-07T15:47:35Z","receivedAt":"2008-06-07T15:47:35Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"\"Nguyen Thai Ngoc Duy\" <pclouds@gmail.com> writes:\n\n> Currently attr.c will read .gitattributes on disk no matter there is a\n> real worktree or not. \n\nCurrently .gitattributes are read _only_ from the work tree.\nThere isn't even infrastructure to read .gitattributes for commit\n(from a tree); git-check-attr, and I guess also internal git API,\ndeals only with in-tree .gitattribute file.\n\n> This can lead to strange behavior. For example when I do\n> \n> mkdir a && cd a\n> git init\n> echo '$Format:%s$' > a\n> git add a && git commit -m initial\n> cd ..\n> echo 'a export-subst' > .gitattributes # let's assume this is an accident.\n> git --git-dir=a/.git archive --format=tar HEAD|tar xO a\n> \n> I expect it to show '$Format:%s$', not \"initial\". git-archive should\n> not bother reading that .gitattributes. I thought an\n> is_inside_work_tree() check would be enough. Unfortunately, setting\n> --git-dir will automatically set worktree too. Any ideas?\n\nAnd it doesn't work at all for bare repositories.\n\nI guess that might have been caused by the fact, that .gitattributes\nare similar to .gitignore file; but in this they are different.  Of\ncourse there is chicken-and-egg problem with attributes affecting\ncheckout...\n\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"},{"id":"79053","messageId":"fcaeb9bf0806070919k105263c8ybc9c04ffd11e3224@mail.gmail.com","threadId":"13849","inReplyTo":"m33anpxn63.fsf@localhost.localdomain","subject":"Re: git-archive and unwanted .gitattributes","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2008-06-07T16:19:20Z","receivedAt":"2008-06-07T16:19:20Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Sat, Jun 7, 2008 at 10:47 PM, Jakub Narebski <jnareb@gmail.com> wrote:\n> \"Nguyen Thai Ngoc Duy\" <pclouds@gmail.com> writes:\n>\n>> Currently attr.c will read .gitattributes on disk no matter there is a\n>> real worktree or not.\n>\n> Currently .gitattributes are read _only_ from the work tree.\n> There isn't even infrastructure to read .gitattributes for commit\n> (from a tree); git-check-attr, and I guess also internal git API,\n> deals only with in-tree .gitattribute file.\n\nI saw it read from index but forgot that index != tree :( So\ngit-archive + export-subst just does not work as expected.\n\n-- \nDuy\n"},{"id":"79120","messageId":"484BF7BB.1090802@lsrfire.ath.cx","threadId":"13849","inReplyTo":"fcaeb9bf0806070821r5ba650c2x1fef7947fc4a2de5@mail.gmail.com","subject":"[PATCH] fix attribute handling in bare repositories","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2008-06-08T15:16:11Z","receivedAt":"2008-06-08T15:16:11Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Nguyen Thai Ngoc Duy schrieb:\n> Hi,\n> \n> Currently attr.c will read .gitattributes on disk no matter there is a\n> real worktree or not. This can lead to strange behavior.\n\nYes, it probably shouldn't do that.  What about this patch?\n\n-- snip! --\nAttributes can be specified at three different places: the internal table\nof default values, the file $GIT_DIR/info/attributes and files named\n.gitattributes in the work tree.  Since bare repositories don't have a\nwork tree, git should ignore any .gitattributes files there.\n\nThis patch makes git do that, so the only way left for a user to specify\nattributes in a bare repository is the file info/attributes (in addition\nto changing the defaults and recompiling).\n\nIn addition, git-check-attr is allowed to run without a work tree.  Like\nany user of the code in attr.c, it simply ignores the .gitattributes\nfiles when run in a bare repository.  And we need the command to work\nthere, because it's used in the tests that this patch adds.\n\nSigned-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n---\n attr.c                |   46 +++++++++++++++++++++++++---------------------\n git.c                 |    2 +-\n t/t0003-attributes.sh |   35 +++++++++++++++++++++++++++++++++++\n 3 files changed, 61 insertions(+), 22 deletions(-)\n\ndiff --git a/attr.c b/attr.c\nindex 1a15fad..0fb47d3 100644\n--- a/attr.c\n+++ b/attr.c\n@@ -438,11 +438,13 @@ static void bootstrap_attr_stack(void)\n \t\telem->prev = attr_stack;\n \t\tattr_stack = elem;\n \n-\t\telem = read_attr(GITATTRIBUTES_FILE, 1);\n-\t\telem->origin = strdup(\"\");\n-\t\telem->prev = attr_stack;\n-\t\tattr_stack = elem;\n-\t\tdebug_push(elem);\n+\t\tif (!is_bare_repository()) {\n+\t\t\telem = read_attr(GITATTRIBUTES_FILE, 1);\n+\t\t\telem->origin = strdup(\"\");\n+\t\t\telem->prev = attr_stack;\n+\t\t\tattr_stack = elem;\n+\t\t\tdebug_push(elem);\n+\t\t}\n \n \t\telem = read_attr_from_file(git_path(INFOATTRIBUTES_FILE), 1);\n \t\tif (!elem)\n@@ -501,22 +503,24 @@ static void prepare_attr_stack(const char *path, int dirlen)\n \t/*\n \t * Read from parent directories and push them down\n \t */\n-\twhile (1) {\n-\t\tchar *cp;\n-\n-\t\tlen = strlen(attr_stack->origin);\n-\t\tif (dirlen <= len)\n-\t\t\tbreak;\n-\t\tmemcpy(pathbuf, path, dirlen);\n-\t\tmemcpy(pathbuf + dirlen, \"/\", 2);\n-\t\tcp = strchr(pathbuf + len + 1, '/');\n-\t\tstrcpy(cp + 1, GITATTRIBUTES_FILE);\n-\t\telem = read_attr(pathbuf, 0);\n-\t\t*cp = '\\0';\n-\t\telem->origin = strdup(pathbuf);\n-\t\telem->prev = attr_stack;\n-\t\tattr_stack = elem;\n-\t\tdebug_push(elem);\n+\tif (!is_bare_repository()) {\n+\t\twhile (1) {\n+\t\t\tchar *cp;\n+\n+\t\t\tlen = strlen(attr_stack->origin);\n+\t\t\tif (dirlen <= len)\n+\t\t\t\tbreak;\n+\t\t\tmemcpy(pathbuf, path, dirlen);\n+\t\t\tmemcpy(pathbuf + dirlen, \"/\", 2);\n+\t\t\tcp = strchr(pathbuf + len + 1, '/');\n+\t\t\tstrcpy(cp + 1, GITATTRIBUTES_FILE);\n+\t\t\telem = read_attr(pathbuf, 0);\n+\t\t\t*cp = '\\0';\n+\t\t\telem->origin = strdup(pathbuf);\n+\t\t\telem->prev = attr_stack;\n+\t\t\tattr_stack = elem;\n+\t\t\tdebug_push(elem);\n+\t\t}\n \t}\n \n \t/*\ndiff --git a/git.c b/git.c\nindex 15a0e71..59f0fcc 100644\n--- a/git.c\n+++ b/git.c\n@@ -286,7 +286,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"checkout-index\", cmd_checkout_index,\n \t\t\tRUN_SETUP | NEED_WORK_TREE},\n \t\t{ \"check-ref-format\", cmd_check_ref_format },\n-\t\t{ \"check-attr\", cmd_check_attr, RUN_SETUP | NEED_WORK_TREE },\n+\t\t{ \"check-attr\", cmd_check_attr, RUN_SETUP },\n \t\t{ \"cherry\", cmd_cherry, RUN_SETUP },\n \t\t{ \"cherry-pick\", cmd_cherry_pick, RUN_SETUP | NEED_WORK_TREE },\n \t\t{ \"clone\", cmd_clone },\ndiff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh\nindex c56d2fb..3d8e06a 100755\n--- a/t/t0003-attributes.sh\n+++ b/t/t0003-attributes.sh\n@@ -54,4 +54,39 @@ test_expect_success 'root subdir attribute test' '\n \n '\n \n+test_expect_success 'setup bare' '\n+\n+\tgit clone --bare . bare.git &&\n+\tcd bare.git\n+\n+'\n+\n+test_expect_success 'bare repository: check that .gitattribute is ignored' '\n+\n+\t(\n+\t\techo \"f\ttest=f\"\n+\t\techo \"a/i test=a/i\"\n+\t) >.gitattributes &&\n+\tattr_check f unspecified &&\n+\tattr_check a/f unspecified &&\n+\tattr_check a/c/f unspecified &&\n+\tattr_check a/i unspecified &&\n+\tattr_check subdir/a/i unspecified\n+\n+'\n+\n+test_expect_success 'bare repository: test info/attributes' '\n+\n+\t(\n+\t\techo \"f\ttest=f\"\n+\t\techo \"a/i test=a/i\"\n+\t) >info/attributes &&\n+\tattr_check f f &&\n+\tattr_check a/f f &&\n+\tattr_check a/c/f f &&\n+\tattr_check a/i a/i &&\n+\tattr_check subdir/a/i unspecified\n+\n+'\n+\n test_done\n"},{"id":"79121","messageId":"484BF9BA.30400@lsrfire.ath.cx","threadId":"13849","inReplyTo":"m33anpxn63.fsf@localhost.localdomain","subject":"Re: git-archive and unwanted .gitattributes","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2008-06-08T15:24:42Z","receivedAt":"2008-06-08T15:24:42Z","isPatch":false,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Jakub Narebski schrieb:\n> \"Nguyen Thai Ngoc Duy\" <pclouds@gmail.com> writes:\n> \n>> Currently attr.c will read .gitattributes on disk no matter there is a\n>> real worktree or not. \n> \n> Currently .gitattributes are read _only_ from the work tree.\n> There isn't even infrastructure to read .gitattributes for commit\n> (from a tree); git-check-attr, and I guess also internal git API,\n> deals only with in-tree .gitattribute file.\n\nAttributes are taken from three places (in order of increasing\nprecedence): a table of built-in defaults, .gitattributes files in the\nwork tree, and the file $GIT_DIR/info/attributes.\n\nRené\n"},{"id":"79157","messageId":"7vskvnirjm.fsf@gitster.siamese.dyndns.org","threadId":"13849","inReplyTo":"484BF7BB.1090802@lsrfire.ath.cx","subject":"Re: [PATCH] fix attribute handling in bare repositories","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-06-08T20:46:05Z","receivedAt":"2008-06-08T20:46:05Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"René Scharfe <rene.scharfe@lsrfire.ath.cx> writes:\n\n> Nguyen Thai Ngoc Duy schrieb:\n>> Hi,\n>> \n>> Currently attr.c will read .gitattributes on disk no matter there is a\n>> real worktree or not. This can lead to strange behavior.\n>\n> Yes, it probably shouldn't do that.  What about this patch?\n\nHmm.  I do not know if it breaks anything, but if you are indeed in a bare\nrepository, the files the codepaths affected try to read would not exist\nanyway, so I am not sure what this would fix, other than changing the\nbehaviour of check-attr from noticing that it was asked for nonsense and\nbail out to not noticing nor saying anything useful.\n"},{"id":"79164","messageId":"484C4FB2.6020105@lsrfire.ath.cx","threadId":"13849","inReplyTo":"7vskvnirjm.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] fix attribute handling in bare repositories","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2008-06-08T21:31:30Z","receivedAt":"2008-06-08T21:31:30Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Junio C Hamano schrieb:\n> René Scharfe <rene.scharfe@lsrfire.ath.cx> writes:\n> \n>> Nguyen Thai Ngoc Duy schrieb:\n>>> Hi,\n>>>\n>>> Currently attr.c will read .gitattributes on disk no matter there is a\n>>> real worktree or not. This can lead to strange behavior.\n>> Yes, it probably shouldn't do that.  What about this patch?\n> \n> Hmm.  I do not know if it breaks anything, but if you are indeed in a bare\n> repository, the files the codepaths affected try to read would not exist\n> anyway, so I am not sure what this would fix, other than changing the\n> behaviour of check-attr from noticing that it was asked for nonsense and\n> bail out to not noticing nor saying anything useful.\n\nThe patch does two things: it fixes git-check-attr to work in a bare\nrepository, and it makes git ignore .gitattributes files in bare\nrepositories.  True, the latter is fixable by simply not creating these\nfiles in the first place.\n\nDuy somehow ended up with them, though, and reported it as strange that\nthey are not ignored.  And I agree: if we don't have a work tree then we\nshould not look at it. :-)\n\nRené\n"},{"id":"79201","messageId":"fcaeb9bf0806082124m604e5280o55bd0fef39345ad1@mail.gmail.com","threadId":"13849","inReplyTo":"7vskvnirjm.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] fix attribute handling in bare repositories","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2008-06-09T04:24:19Z","receivedAt":"2008-06-09T04:24:19Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Mon, Jun 9, 2008 at 3:46 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> René Scharfe <rene.scharfe@lsrfire.ath.cx> writes:\n>\n>> Nguyen Thai Ngoc Duy schrieb:\n>>> Hi,\n>>>\n>>> Currently attr.c will read .gitattributes on disk no matter there is a\n>>> real worktree or not. This can lead to strange behavior.\n>>\n>> Yes, it probably shouldn't do that.  What about this patch?\n>\n> Hmm.  I do not know if it breaks anything, but if you are indeed in a bare\n> repository, the files the codepaths affected try to read would not exist\n> anyway, so I am not sure what this would fix, other than changing the\n> behaviour of check-attr from noticing that it was asked for nonsense and\n> bail out to not noticing nor saying anything useful.\n\nYes. But just in case those .gitattributes exist by accident (for\nexample you access a bare repository from a worktree of another\nrepository). I don't want to check cwd for .gitattributes everytime I\nwant to use git-archive :)\n\nAnyway if I do \"git-archive <commit>\" it should read .gitattributes\nfrom that commit, not from working directory.\n-- \nDuy\n"}]}