All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] optionally disable gitattributes
@ 2016-01-27  9:50 Clemens Buchacher
  2016-01-27 11:59 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Clemens Buchacher @ 2016-01-27  9:50 UTC (permalink / raw)
  To: git; +Cc: gitster

If committed files are not normalized, adding gitattributes has the
side effect that such files are shown as modified, even though they
were not actually modified by the user, and the work tree matches
the committed file. This is because with gitattributes, the file is
modified on the fly when git reads it from disk, before it compares
with the index contents.

This is desirable in most situations, because it makes the user
aware that files should be normalized. However, it can become an
issue for automation. Since Git considers the work tree to be
dirty, some operations such as git rebase or git cherry-pick refuse
to operate. Those commands offer no flag to force overwrite work
tree changes. The only options are to commit the changes, or to
remove gitattributes, but that changes the repository state, which
may be undesirable in a scripted context.

Introduce an environment variable GIT_ATTRIBUTES_DISABLED, which if
set makes Git ignore any gitattributes.

Signed-off-by: Clemens Buchacher <drizzd@aon.at>
---
 Documentation/git.txt           |  4 ++++
 Documentation/gitattributes.txt |  6 ++++++
 attr.c                          |  3 +++
 t/t0003-attributes.sh           | 43 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 56 insertions(+)

diff --git a/Documentation/git.txt b/Documentation/git.txt
index bff6302..00f4e3b 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -1132,6 +1132,10 @@ of clones and fetches.
 	  - any external helpers are named by their protocol (e.g., use
 	    `hg` to allow the `git-remote-hg` helper)
 
+'GIT_ATTRIBUTES_DISABLED'::
+	If set, attributes are disabled for all paths. See
+	linkgit:gitattributes[1] for more details on attributes.
+
 
 Discussion[[Discussion]]
 ------------------------
diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index e3b1de8..f6a2b1d 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -996,6 +996,12 @@ frotz	unspecified
 ----------------------------------------------------------------
 
 
+ENVIRONMENT
+-----------
+
+GIT_ATTRIBUTES_DISABLED::
+	If set, attributes are disabled for all paths.
+
 SEE ALSO
 --------
 linkgit:git-check-attr[1].
diff --git a/attr.c b/attr.c
index 086c08d..0fa2f1a 100644
--- a/attr.c
+++ b/attr.c
@@ -547,6 +547,9 @@ static void prepare_attr_stack(const char *path, int dirlen)
 	int len;
 	const char *cp;
 
+	if (getenv("GIT_ATTRIBUTES_DISABLED"))
+		return;
+
 	/*
 	 * At the bottom of the attribute stack is the built-in
 	 * set of attribute definitions, followed by the contents
diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh
index f0fbb42..26e6766 100755
--- a/t/t0003-attributes.sh
+++ b/t/t0003-attributes.sh
@@ -13,6 +13,14 @@ attr_check () {
 	test_line_count = 0 err
 }
 
+attr_check_disabled () {
+	(
+		GIT_ATTRIBUTES_DISABLED=t
+		export GIT_ATTRIBUTES_DISABLED
+		attr_check "$@" unspecified
+	)
+}
+
 test_expect_success 'setup' '
 	mkdir -p a/b/d a/c b &&
 	(
@@ -84,6 +92,41 @@ test_expect_success 'attribute test' '
 	attr_check a/b/d/yes unspecified
 '
 
+test_expect_success 'gitattributes disabled' '
+	attr_check_disabled f &&
+	attr_check_disabled a/f &&
+	attr_check_disabled a/c/f &&
+	attr_check_disabled a/g &&
+	attr_check_disabled a/b/g &&
+	attr_check_disabled b/g &&
+	attr_check_disabled a/b/h &&
+	attr_check_disabled a/b/d/g &&
+	attr_check_disabled onoff &&
+	attr_check_disabled offon &&
+	attr_check_disabled no &&
+	attr_check_disabled a/b/d/no &&
+	attr_check_disabled a/b/d/yes
+'
+
+test_expect_success 'no changes if gitattributes disabled' '
+	mkdir clean &&
+	git init clean &&
+	(
+		cd clean &&
+		printf "foo\r\n" >dos.txt &&
+		git add dos.txt &&
+		test_tick &&
+		git commit -q -m dos.txt &&
+		echo "*.txt text eol=lf" >.gitattributes &&
+		git add .gitattributes &&
+		test_tick &&
+		git commit -q -m .gitattributes &&
+		rm -f .git/index &&
+		git reset &&
+		GIT_ATTRIBUTES_DISABLED=t git diff --exit-code
+	)
+'
+
 test_expect_success 'attribute matching is case sensitive when core.ignorecase=0' '
 
 	test_must_fail attr_check F f "-c core.ignorecase=0" &&
-- 
2.7.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] optionally disable gitattributes
  2016-01-27  9:50 [PATCH] optionally disable gitattributes Clemens Buchacher
@ 2016-01-27 11:59 ` Junio C Hamano
  2016-01-27 15:04   ` Torsten Bögershausen
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2016-01-27 11:59 UTC (permalink / raw)
  To: Clemens Buchacher; +Cc: git

Clemens Buchacher <drizzd@aon.at> writes:

> If committed files are not normalized, adding gitattributes has the
> side effect that such files are shown as modified, even though they
> were not actually modified by the user, and the work tree matches
> the committed file. This is because with gitattributes, the file is
> modified on the fly when git reads it from disk, before it compares
> with the index contents.
>
> This is desirable in most situations, because it makes the user
> aware that files should be normalized. However, it can become an
> issue for automation. Since Git considers the work tree to be
> dirty, some operations such as git rebase or git cherry-pick refuse
> to operate. Those commands offer no flag to force overwrite work
> tree changes. The only options are to commit the changes, or to
> remove gitattributes, but that changes the repository state, which
> may be undesirable in a scripted context.
>
> Introduce an environment variable GIT_ATTRIBUTES_DISABLED, which if
> set makes Git ignore any gitattributes.
>
> Signed-off-by: Clemens Buchacher <drizzd@aon.at>
> ---

Is the problem you are trying to solve related to the issue we
discussed recently in a nearby thread?

That is, even after "reset --hard", if the result of converting the
contents in the index to the working tree representation and then
converting that result back to the normalized representation does
not match what is in the index, Git would sometimes say that the
working tree contents differ from the index?

I think the change in this patch has some uses, and I think the
issue we discussed recently in a nearby thread indeed is a problem,
but I do not think there is an impedance mismatch beween the two, so
I'd like to first make sure you are trying to solve the problem I
think you are trying to solve.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] optionally disable gitattributes
  2016-01-27 11:59 ` Junio C Hamano
@ 2016-01-27 15:04   ` Torsten Bögershausen
  2016-01-27 15:25     ` Clemens Buchacher
  0 siblings, 1 reply; 4+ messages in thread
From: Torsten Bögershausen @ 2016-01-27 15:04 UTC (permalink / raw)
  To: Junio C Hamano, Clemens Buchacher; +Cc: git

On 27.01.16 12:59, Junio C Hamano wrote:
> Clemens Buchacher <drizzd@aon.at> writes:
> 
>> If committed files are not normalized, adding gitattributes has the
>> side effect that such files are shown as modified, even though they
>> were not actually modified by the user, and the work tree matches
>> the committed file. This is because with gitattributes, the file is
>> modified on the fly when git reads it from disk, before it compares
>> with the index contents.
>>
>> This is desirable in most situations, because it makes the user
>> aware that files should be normalized. However, it can become an
>> issue for automation. Since Git considers the work tree to be
>> dirty, some operations such as git rebase or git cherry-pick refuse
>> to operate. Those commands offer no flag to force overwrite work
>> tree changes. The only options are to commit the changes, or to
>> remove gitattributes, but that changes the repository state, which
>> may be undesirable in a scripted context.
It feels like a workaround for something that could be fixable, or is already ongoing.
Before going into more details,
could you tell us which attributes you are typically using (when having this problems) ?
Is it
* text=auto
or
*.sh text 
or something else?


>>
>> Introduce an environment variable GIT_ATTRIBUTES_DISABLED, which if
>> set makes Git ignore any gitattributes.
>>
>> Signed-off-by: Clemens Buchacher <drizzd@aon.at>
>> ---
> 
> Is the problem you are trying to solve related to the issue we
> discussed recently in a nearby thread?
It seems that I missed the thread ?
> 
> That is, even after "reset --hard", if the result of converting the
> contents in the index to the working tree representation and then
> converting that result back to the normalized representation does
> not match what is in the index, Git would sometimes say that the
> working tree contents differ from the index?
> 
> I think the change in this patch has some uses, and I think the
> issue we discussed recently in a nearby thread indeed is a problem,
> but I do not think there is an impedance mismatch beween the two, so
> I'd like to first make sure you are trying to solve the problem I
> think you are trying to solve.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] optionally disable gitattributes
  2016-01-27 15:04   ` Torsten Bögershausen
@ 2016-01-27 15:25     ` Clemens Buchacher
  0 siblings, 0 replies; 4+ messages in thread
From: Clemens Buchacher @ 2016-01-27 15:25 UTC (permalink / raw)
  To: Torsten Bögershausen; +Cc: Junio C Hamano, git

On Wed, Jan 27, 2016 at 04:04:39PM +0100, Torsten Bögershausen wrote:
>
> It feels like a workaround for something that could be fixable, or is already ongoing.
> Before going into more details,
> could you tell us which attributes you are typically using (when having this problems) ?
> Is it
> * text=auto
> or
> *.sh text 
> or something else?

My concrete use case is the text attribute, as in your example: "*.sh
text". But I think of the patch as a more general solution for cases
where we want to work with the files as they are committed, without
having to deal with not normalized files or other conversions due to
gitattributes.

Please note that you may also want to read my reply to the other thread
that Junio mentioned: [PATCH] travis-ci: run previously failed tests
first, then slowest to fastest.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-01-27 15:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-27  9:50 [PATCH] optionally disable gitattributes Clemens Buchacher
2016-01-27 11:59 ` Junio C Hamano
2016-01-27 15:04   ` Torsten Bögershausen
2016-01-27 15:25     ` Clemens Buchacher

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.