{"thread":{"id":"41266","subject":"[PATCH] optionally disable gitattributes","startedAt":"2016-01-27T09:50:21Z","lastAt":"2016-01-27T15:25:54Z","messageCount":4,"participants":["Clemens Buchacher","Junio C Hamano","Torsten Bögershausen"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"276883","messageId":"20160127095021.GA25281@ecki.hitronhub.home","threadId":"41266","inReplyTo":null,"subject":"[PATCH] optionally disable gitattributes","fromName":"Clemens Buchacher","fromEmail":"drizzd@aon.at","sentAt":"2016-01-27T09:50:21Z","receivedAt":"2016-01-27T09:50:21Z","isPatch":true,"sender":{"key":"drizzd@gmx.net","avatar":"https://avatars.githubusercontent.com/u/59082?v=4"},"body":"If committed files are not normalized, adding gitattributes has the\nside effect that such files are shown as modified, even though they\nwere not actually modified by the user, and the work tree matches\nthe committed file. This is because with gitattributes, the file is\nmodified on the fly when git reads it from disk, before it compares\nwith the index contents.\n\nThis is desirable in most situations, because it makes the user\naware that files should be normalized. However, it can become an\nissue for automation. Since Git considers the work tree to be\ndirty, some operations such as git rebase or git cherry-pick refuse\nto operate. Those commands offer no flag to force overwrite work\ntree changes. The only options are to commit the changes, or to\nremove gitattributes, but that changes the repository state, which\nmay be undesirable in a scripted context.\n\nIntroduce an environment variable GIT_ATTRIBUTES_DISABLED, which if\nset makes Git ignore any gitattributes.\n\nSigned-off-by: Clemens Buchacher <drizzd@aon.at>\n---\n Documentation/git.txt           |  4 ++++\n Documentation/gitattributes.txt |  6 ++++++\n attr.c                          |  3 +++\n t/t0003-attributes.sh           | 43 +++++++++++++++++++++++++++++++++++++++++\n 4 files changed, 56 insertions(+)\n\ndiff --git a/Documentation/git.txt b/Documentation/git.txt\nindex bff6302..00f4e3b 100644\n--- a/Documentation/git.txt\n+++ b/Documentation/git.txt\n@@ -1132,6 +1132,10 @@ of clones and fetches.\n \t  - any external helpers are named by their protocol (e.g., use\n \t    `hg` to allow the `git-remote-hg` helper)\n \n+'GIT_ATTRIBUTES_DISABLED'::\n+\tIf set, attributes are disabled for all paths. See\n+\tlinkgit:gitattributes[1] for more details on attributes.\n+\n \n Discussion[[Discussion]]\n ------------------------\ndiff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt\nindex e3b1de8..f6a2b1d 100644\n--- a/Documentation/gitattributes.txt\n+++ b/Documentation/gitattributes.txt\n@@ -996,6 +996,12 @@ frotz\tunspecified\n ----------------------------------------------------------------\n \n \n+ENVIRONMENT\n+-----------\n+\n+GIT_ATTRIBUTES_DISABLED::\n+\tIf set, attributes are disabled for all paths.\n+\n SEE ALSO\n --------\n linkgit:git-check-attr[1].\ndiff --git a/attr.c b/attr.c\nindex 086c08d..0fa2f1a 100644\n--- a/attr.c\n+++ b/attr.c\n@@ -547,6 +547,9 @@ static void prepare_attr_stack(const char *path, int dirlen)\n \tint len;\n \tconst char *cp;\n \n+\tif (getenv(\"GIT_ATTRIBUTES_DISABLED\"))\n+\t\treturn;\n+\n \t/*\n \t * At the bottom of the attribute stack is the built-in\n \t * set of attribute definitions, followed by the contents\ndiff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh\nindex f0fbb42..26e6766 100755\n--- a/t/t0003-attributes.sh\n+++ b/t/t0003-attributes.sh\n@@ -13,6 +13,14 @@ attr_check () {\n \ttest_line_count = 0 err\n }\n \n+attr_check_disabled () {\n+\t(\n+\t\tGIT_ATTRIBUTES_DISABLED=t\n+\t\texport GIT_ATTRIBUTES_DISABLED\n+\t\tattr_check \"$@\" unspecified\n+\t)\n+}\n+\n test_expect_success 'setup' '\n \tmkdir -p a/b/d a/c b &&\n \t(\n@@ -84,6 +92,41 @@ test_expect_success 'attribute test' '\n \tattr_check a/b/d/yes unspecified\n '\n \n+test_expect_success 'gitattributes disabled' '\n+\tattr_check_disabled f &&\n+\tattr_check_disabled a/f &&\n+\tattr_check_disabled a/c/f &&\n+\tattr_check_disabled a/g &&\n+\tattr_check_disabled a/b/g &&\n+\tattr_check_disabled b/g &&\n+\tattr_check_disabled a/b/h &&\n+\tattr_check_disabled a/b/d/g &&\n+\tattr_check_disabled onoff &&\n+\tattr_check_disabled offon &&\n+\tattr_check_disabled no &&\n+\tattr_check_disabled a/b/d/no &&\n+\tattr_check_disabled a/b/d/yes\n+'\n+\n+test_expect_success 'no changes if gitattributes disabled' '\n+\tmkdir clean &&\n+\tgit init clean &&\n+\t(\n+\t\tcd clean &&\n+\t\tprintf \"foo\\r\\n\" >dos.txt &&\n+\t\tgit add dos.txt &&\n+\t\ttest_tick &&\n+\t\tgit commit -q -m dos.txt &&\n+\t\techo \"*.txt text eol=lf\" >.gitattributes &&\n+\t\tgit add .gitattributes &&\n+\t\ttest_tick &&\n+\t\tgit commit -q -m .gitattributes &&\n+\t\trm -f .git/index &&\n+\t\tgit reset &&\n+\t\tGIT_ATTRIBUTES_DISABLED=t git diff --exit-code\n+\t)\n+'\n+\n test_expect_success 'attribute matching is case sensitive when core.ignorecase=0' '\n \n \ttest_must_fail attr_check F f \"-c core.ignorecase=0\" &&\n-- \n2.7.0\n"},{"id":"276886","messageId":"xmqqy4bb8c86.fsf@gitster.mtv.corp.google.com","threadId":"41266","inReplyTo":"20160127095021.GA25281@ecki.hitronhub.home","subject":"Re: [PATCH] optionally disable gitattributes","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-01-27T11:59:21Z","receivedAt":"2016-01-27T11:59:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Clemens Buchacher <drizzd@aon.at> writes:\n\n> If committed files are not normalized, adding gitattributes has the\n> side effect that such files are shown as modified, even though they\n> were not actually modified by the user, and the work tree matches\n> the committed file. This is because with gitattributes, the file is\n> modified on the fly when git reads it from disk, before it compares\n> with the index contents.\n>\n> This is desirable in most situations, because it makes the user\n> aware that files should be normalized. However, it can become an\n> issue for automation. Since Git considers the work tree to be\n> dirty, some operations such as git rebase or git cherry-pick refuse\n> to operate. Those commands offer no flag to force overwrite work\n> tree changes. The only options are to commit the changes, or to\n> remove gitattributes, but that changes the repository state, which\n> may be undesirable in a scripted context.\n>\n> Introduce an environment variable GIT_ATTRIBUTES_DISABLED, which if\n> set makes Git ignore any gitattributes.\n>\n> Signed-off-by: Clemens Buchacher <drizzd@aon.at>\n> ---\n\nIs the problem you are trying to solve related to the issue we\ndiscussed recently in a nearby thread?\n\nThat is, even after \"reset --hard\", if the result of converting the\ncontents in the index to the working tree representation and then\nconverting that result back to the normalized representation does\nnot match what is in the index, Git would sometimes say that the\nworking tree contents differ from the index?\n\nI think the change in this patch has some uses, and I think the\nissue we discussed recently in a nearby thread indeed is a problem,\nbut I do not think there is an impedance mismatch beween the two, so\nI'd like to first make sure you are trying to solve the problem I\nthink you are trying to solve.\n"},{"id":"276889","messageId":"56A8DC87.2080307@web.de","threadId":"41266","inReplyTo":"xmqqy4bb8c86.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] optionally disable gitattributes","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2016-01-27T15:04:39Z","receivedAt":"2016-01-27T15:04:39Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"On 27.01.16 12:59, Junio C Hamano wrote:\n> Clemens Buchacher <drizzd@aon.at> writes:\n> \n>> If committed files are not normalized, adding gitattributes has the\n>> side effect that such files are shown as modified, even though they\n>> were not actually modified by the user, and the work tree matches\n>> the committed file. This is because with gitattributes, the file is\n>> modified on the fly when git reads it from disk, before it compares\n>> with the index contents.\n>>\n>> This is desirable in most situations, because it makes the user\n>> aware that files should be normalized. However, it can become an\n>> issue for automation. Since Git considers the work tree to be\n>> dirty, some operations such as git rebase or git cherry-pick refuse\n>> to operate. Those commands offer no flag to force overwrite work\n>> tree changes. The only options are to commit the changes, or to\n>> remove gitattributes, but that changes the repository state, which\n>> may be undesirable in a scripted context.\nIt feels like a workaround for something that could be fixable, or is already ongoing.\nBefore going into more details,\ncould you tell us which attributes you are typically using (when having this problems) ?\nIs it\n* text=auto\nor\n*.sh text \nor something else?\n\n\n>>\n>> Introduce an environment variable GIT_ATTRIBUTES_DISABLED, which if\n>> set makes Git ignore any gitattributes.\n>>\n>> Signed-off-by: Clemens Buchacher <drizzd@aon.at>\n>> ---\n> \n> Is the problem you are trying to solve related to the issue we\n> discussed recently in a nearby thread?\nIt seems that I missed the thread ?\n> \n> That is, even after \"reset --hard\", if the result of converting the\n> contents in the index to the working tree representation and then\n> converting that result back to the normalized representation does\n> not match what is in the index, Git would sometimes say that the\n> working tree contents differ from the index?\n> \n> I think the change in this patch has some uses, and I think the\n> issue we discussed recently in a nearby thread indeed is a problem,\n> but I do not think there is an impedance mismatch beween the two, so\n> I'd like to first make sure you are trying to solve the problem I\n> think you are trying to solve.\n"},{"id":"276893","messageId":"20160127152553.GA2380@ecki.hitronhub.home","threadId":"41266","inReplyTo":"56A8DC87.2080307@web.de","subject":"Re: [PATCH] optionally disable gitattributes","fromName":"Clemens Buchacher","fromEmail":"drizzd@aon.at","sentAt":"2016-01-27T15:25:54Z","receivedAt":"2016-01-27T15:25:54Z","isPatch":true,"sender":{"key":"drizzd@gmx.net","avatar":"https://avatars.githubusercontent.com/u/59082?v=4"},"body":"On Wed, Jan 27, 2016 at 04:04:39PM +0100, Torsten Bögershausen wrote:\n>\n> It feels like a workaround for something that could be fixable, or is already ongoing.\n> Before going into more details,\n> could you tell us which attributes you are typically using (when having this problems) ?\n> Is it\n> * text=auto\n> or\n> *.sh text \n> or something else?\n\nMy concrete use case is the text attribute, as in your example: \"*.sh\ntext\". But I think of the patch as a more general solution for cases\nwhere we want to work with the files as they are committed, without\nhaving to deal with not normalized files or other conversions due to\ngitattributes.\n\nPlease note that you may also want to read my reply to the other thread\nthat Junio mentioned: [PATCH] travis-ci: run previously failed tests\nfirst, then slowest to fastest.\n"}]}