git/list[1] front-page[2] threads[3] people[4] search[5] about
 

attr.c doesn't honor --work-tree option

From
Lasse Makholm <lasse.makholm@gmail.com>
Date
Feb 6, 2014, 12:48 UTC
Message-ID
<CAB7pA0_2kLJmRZb8Z_9+xOcrbwMZLgnZwC5f7etbE4OuJ1wgmA@mail.gmail.com>
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
Next: Junio C Hamano
Message 1 of 13 in “attr.c doesn't honor --work-tree option”
  1. Lasse MakholmFeb 6, 2014
  2. Junio C HamanoFeb 6, 2014
  3. 1/2 t0003: do not chdir the whole test processJunio C Hamano, Feb 6, 2014
  4. 2/2 check-attr: move to the top of working tree when in non-bare repositoryJunio C Hamano, Feb 6, 2014
  5. Jonathan NiederFeb 6, 2014
  6. Jonathan NiederFeb 6, 2014
  7. Junio C HamanoFeb 6, 2014
  8. Michael HaggertyFeb 16, 2014
  9. Jonathan NiederFeb 6, 2014
  10. Junio C HamanoFeb 6, 2014
  11. Jonathan NiederFeb 6, 2014
  12. Junio C HamanoFeb 6, 2014
  13. Lasse MakholmFeb 10, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.