From: Junio C Hamano <hidden> Date: 2016-06-15 22:59:50
Lasse Makholm [off-list ref] writes:
Here's a repro with -DDEBUG_ATTR=1 and a printf() in read_attr_from_file():
$ cd /tmp/
$ mkdir -p attr-test/repo
$ cd attr-test/repo
$ git init
Initialized empty Git repository in /tmp/attr-test/repo/.git/
$ echo 'dir/* filter=foo' >.gitattributes
$
Inside the working tree, it works:
$ ~/src/git.git/git check-attr -a dir/file
Does check-ignore misbehave the same way?
I suspect that is this because check-attr is not a command that
requires a working tree. The command was written primarily as a
debugging aid that can be used anywhere as long as you have a
repository to read strings from either its standard input or its
arguments, and gives them directly to check_attr(), but it does so
without first going to the top of the real working tree like
check-ignore does.
Forcing it to go to the top of the working tree (see the attached
one-liner, but note that I didn't test it) may give you want you
want.
git.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Junio C Hamano <hidden> Date: 2016-06-15 22:59:50
Moving to some other directory and letting the remainder of the test
pieces to expect that they start there is a bad practice. The test
that contains chdir itself may fail (or by mistake skipped via the
GIT_SKIP_TESTS mechanism) in which case the remainder may operate on
files in unexpected places.
Signed-off-by: Junio C Hamano <redacted>
---
* This is purely a preparatory clean-up in the test script I'll be
adding a new test to in the next patch.
t/t0003-attributes.sh | 52 +++++++++++++++++++++++++++++----------------------
1 file changed, 30 insertions(+), 22 deletions(-)
From: Junio C Hamano <hidden> Date: 2016-06-15 22:59:50
Lasse Makholm noticed that running "git check-attr" from a place
totally unrelated to $GIT_DIR and $GIT_WORK_TREE does not give
expected results. I think it is because the command does not say it
wants to call setup_work_tree().
We still need to support use cases where only a bare repository is
involved, so unconditionally requiring a working tree would not work
well. Instead, make a call only in a non-bare repository.
We may want to see if we want to do a similar fix in the opposite
direction to check-ignore. The command unconditionally requires a
working tree, but it should be usable in a bare repository just like
check-attr attempts to be.
Signed-off-by: Junio C Hamano <redacted>
---
builtin/check-attr.c | 3 +++
t/t0003-attributes.sh | 10 ++++++++++
2 files changed, 13 insertions(+)
From: Jonathan Nieder <hidden> Date: 2016-06-15 22:59:51
Junio C Hamano wrote:
Moving to some other directory and letting the remainder of the test
pieces to expect that they start there is a bad practice.
I agree with the above, and I like the patch...
The test
that contains chdir itself may fail (or by mistake skipped via the
GIT_SKIP_TESTS mechanism) in which case the remainder may operate on
files in unexpected places.
... but this logic seems wrong. I don't think we've ever supported
setup tests failing or being skipped in the past.
Thanks,
Jonathan
Someone asked in a private reply how this interacts with t0003.
t0003 tries check-attr in a bare repository. The question is, is that
a desirable feature, and are people relying on it? If people are
relying on it, perhaps the intuitive behavior would be to make
check-attr use an only-look-at-HEAD mode by default when running in a
bare repo.
How do I use the only-look-at-HEAD mode from a non-bare repo? If I
want attributes with respect to some other commit instead of HEAD, is
there a syntax for that? The command doesn't seem to have been well
thought out.
Hope that helps,
Jonathan
From: Lasse Makholm <hidden> Date: 2016-06-15 22:59:52
On 6 February 2014 18:54, Junio C Hamano [off-list ref] wrote:
Lasse Makholm [off-list ref] writes:
quoted
Here's a repro with -DDEBUG_ATTR=1 and a printf() in read_attr_from_file():
$ cd /tmp/
$ mkdir -p attr-test/repo
$ cd attr-test/repo
$ git init
Initialized empty Git repository in /tmp/attr-test/repo/.git/
$ echo 'dir/* filter=foo' >.gitattributes
$
Inside the working tree, it works:
$ ~/src/git.git/git check-attr -a dir/file
Does check-ignore misbehave the same way?
No, check-ignore works but also has NEED_WORK_TREE set. And that
actually also feels a bit wrong to me because check-attr and
check-ignore both seem like reasonable things to do in a bare repo
because .git(attributes|ignore) files are likely to be committed in
the repo.
I suspect that is this because check-attr is not a command that
requires a working tree. The command was written primarily as a
debugging aid that can be used anywhere as long as you have a
repository to read strings from either its standard input or its
arguments, and gives them directly to check_attr(), but it does so
without first going to the top of the real working tree like
check-ignore does.
Fair point. I actually stumbled across this because a git cat-file
--textconv ... was failing, so that's at least one other (and arguably
more real) use case that is broken in the same way.
Forcing it to go to the top of the working tree (see the attached
one-liner, but note that I didn't test it) may give you want you
want.
For this case, it does, yes. But it also breaks check-attr in bare
repos with attributes defined in $GIT_DIR/info/attributes because it
will refuse to run without a work tree...
In any case the current state seems broken because --work-tree clearly
doesn't work for all commands...
Setting NEED_WORK_TREE for check-attr risks breaking existing scripts
but on the other hand there doesn't seem to be any good reason why
check-attr and check-ignore should differ in this regard...
It seems like the ideal solution would be an optional NEED_WORK_TREE
of some sort that would let these commands work correctly both with
--work-tree, without it and in bare repos but I get that that might
not be easy to fix...
Another approach might be to deprecate --work-tree and tell people to
use -C instead...
/L
From: Michael Haggerty <hidden> Date: 2016-06-15 22:59:55
On 02/06/2014 09:17 PM, Jonathan Nieder wrote:
How do I use the only-look-at-HEAD mode from a non-bare repo? If I
want attributes with respect to some other commit instead of HEAD, is
there a syntax for that? The command doesn't seem to have been well
thought out.
I agree that it would be nice for "git check-attr" to handle this case.
Currently, I believe that one has to resort to a temporary index file
via something like
(
export GIT_INDEX_FILE="$(mktemp)"
git read-tree HEAD
git check-attr --cached ...
rm "$GIT_INDEX_FILE"
)
Michael
--
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/