Subject: Re: attr.c doesn't honor --work-tree option

From: Junio C Hamano <[email-masked]>
Date: Thu, 06 Feb 2014 09:54:19 -0800

Lasse Makholm <[email-masked]> 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(-)

diff --git a/git.c b/git.c
index 7cf2953..314ec9f 100644
--- a/git.c
+++ b/git.c
@@ -342,7 +342,7 @@ static struct cmd_struct commands[] = {
 	{ "branch", cmd_branch, RUN_SETUP },
 	{ "bundle", cmd_bundle, RUN_SETUP_GENTLY },
 	{ "cat-file", cmd_cat_file, RUN_SETUP },
-	{ "check-attr", cmd_check_attr, RUN_SETUP },
+	{ "check-attr", cmd_check_attr, RUN_SETUP | NEED_WORK_TREE },
 	{ "check-ignore", cmd_check_ignore, RUN_SETUP | NEED_WORK_TREE },
 	{ "check-mailmap", cmd_check_mailmap, RUN_SETUP },
 	{ "check-ref-format", cmd_check_ref_format },