git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* attr.c doesn't honor --work-tree option
@ 2014-02-06 12:48 Lasse Makholm
  2014-02-06 17:54 ` Junio C Hamano
  0 siblings, 1 reply; 13+ messages in thread
From: Lasse Makholm @ 2014-02-06 12:48 UTC (permalink / raw)
  To: Git Mailing List

Hi,

It seems that code in attr.c does not honor the current work tree path
(set by e.g. --work-tree ...) and simply always assumes CWD. When the
current dir is not in the work tree, git will attempt to find
.gitattributes under ./ instead of under the correct work tree.

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
read_attr_from_file: /home/lasse/etc/gitattributes
read_attr_from_file: /home/lasse/.config/git/attributes
read_attr_from_file: .gitattributes
push:
read_attr_from_file: .git/info/attributes
read_attr_from_file: dir/.gitattributes
push: dir
fill: filter => foo (dir/*)
dir/file: filter: foo
$

Outside, it fails to find the .gitattributes file:

$ cd ..
$ ~/src/git.git/git --work-tree /tmp/attr-test/repo --git-dir
/tmp/attr-test/repo/.git check-attr -a dir/file
read_attr_from_file: /home/lasse/etc/gitattributes
read_attr_from_file: /home/lasse/.config/git/attributes
read_attr_from_file: .gitattributes
push:
read_attr_from_file: /tmp/attr-test/repo/.git/info/attributes
read_attr_from_file: dir/.gitattributes
push: dir
$

This is with the latest rev on master:

$ ~/src/git.git/git --version
git version 1.8.5.2.192.g7794a68.dirty
$

It (sort of) works with a committed .gitattributes file because git
will find it in the index, but that will still yield incorrect results
if the .gitattributes file happens to be dirty.

Looking at the code, I'm not really sure if this can be fixed in
read_attr_from_file() by resolving relative paths against
get_git_work_tree(). I doubt it's that simple though...

Thoughts?

/Lasse

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

end of thread, other threads:[~2014-02-16 11:15 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-06 12:48 attr.c doesn't honor --work-tree option Lasse Makholm
2014-02-06 17:54 ` Junio C Hamano
2014-02-06 18:40   ` [PATCH 1/2] t0003: do not chdir the whole test process Junio C Hamano
2014-02-06 18:40     ` [PATCH 2/2] check-attr: move to the top of working tree when in non-bare repository Junio C Hamano
2014-02-06 19:53       ` Jonathan Nieder
2014-02-06 20:17         ` Jonathan Nieder
2014-02-06 20:32           ` Junio C Hamano
2014-02-16 11:15           ` Michael Haggerty
2014-02-06 19:45     ` [PATCH 1/2] t0003: do not chdir the whole test process Jonathan Nieder
2014-02-06 20:25       ` Junio C Hamano
2014-02-06 20:31         ` Jonathan Nieder
2014-02-06 21:26           ` Junio C Hamano
2014-02-10 12:57   ` attr.c doesn't honor --work-tree option Lasse Makholm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).