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

Re: How to use git attributes to configure server-side checks?

From
Jay Soffian <jaysoffian@gmail.com>
Date
Sep 22, 2011, 18:41 UTC
Message-ID
<CAG+J_DxdP2qHhttJOtWQTKeiDV2YbC_A_F+b9sDOZsWhWxjcjw@mail.gmail.com>
In-Reply-To
<20110922171340.GA2934@sigill.intra.peff.net>
On Thu, Sep 22, 2011 at 1:13 PM, Jeff King <peff@peff.net> wrote:
Show 12 quoted lines
>
> No, we definitely don't use in-tree gitattributes. IIRC, there are some
> precedence and ordering questions. I think the ordering now is:
>
>  1. Look in $GIT_DIR/info/attributes
>
>  2. If not found, look in per-directory .gitattributes
>
>  3. If not found, look in core.gitattributesfile
>
> Where do in-tree attributes fit in? Between 1 and 2? Or 2 and 3? And
> which tree do we look at?
attr.c says:
  a. built-in attributes
  b. $(prefix)/etc/gitattributes unless GIT_ATTR_NOSYSTEM is set
  c. core.attributesfile
  d. per-directory .gitattributes
  e. $GIT_DIR/info/attributes
The mechanics of (d) are established by git_attr_direction:
  GIT_ATTR_CHECKIN: working-copy, then index
  GIT_ATTR_CHECKOUT: index, then working-copy
  GIT_ATTR_INDEX: index-only

Where GIT_ATTR_CHECKIN is the default direction and GIT_ATTR_CHECKOUT is used while checking-out files from the index. (GIT_ATTR_INDEX is used only by git-archive.)

Note that (d) only occurs in non-bare repos or if direction is GIT_ATTR_INDEX.
Show 27 quoted lines
> Here are some examples:
>
>  a. If I do "git checkout branch-foo", we should look at branch-foo's
>     tree for things like crlf, right?  Do we still fall back to
>     per-directory .gitattributes in the working tree? On the one hand,
>     they're not really relevant to the commit we're moving to. But they
>     are respected in the current code, and can be useful when moving to
>     old commits which lack attributes.
>
>     I think this is where the index magic comes in in the current code
>     (we do something like "load the index, then respect gitattributes
>     from the index").
>
>     So maybe this is solved already.
>
>  b. You're diffing commit $a against commit $b. Whose gitattributes
>     have precedence? Is order important? Are gitattributes in the
>     working tree and index relevant?
>
>  c. You're diffing commit $a against HEAD. Which gitattributes have
>     precedence? Again, is order important (i.e., does "diff -R" look at
>     different attributes than "diff")?
>
> I'm sure there are others, too. And I don't think any of these is
> insurmountable. But somebody needs to think through a lot of cases and
> come up with consistent, sane behavior that does the right thing in each
> case (considering both bare repositories and ones with working trees).

I think that diff-index --cached or when there is no working tree, should set the direction to GIT_ATTR_INDEX so that it may be used with a bare repo. In such case, the .gitattributes would come from the index.

Consistent with that, when comparing two commits (diff-tree), I think you look at the .gitattributes in the second commit.

j.
Previous: Jeff KingNext: Junio C Hamano
Message 7 of 31 in “How to use git attributes to configure server-side checks?”
  1. Michael HaggertySep 21, 2011
  2. Jay SoffianSep 21, 2011
  3. Junio C HamanoSep 21, 2011
  4. Michael HaggertySep 22, 2011
  5. Jay SoffianSep 22, 2011
  6. Jeff KingSep 22, 2011
  7. Jay SoffianSep 22, 2011
  8. Junio C HamanoSep 22, 2011
  9. Jeff KingSep 22, 2011
  10. Jeff KingSep 22, 2011
  11. Michael HaggertySep 23, 2011
  12. Jeff KingSep 23, 2011
  13. Junio C HamanoSep 23, 2011
  14. Jeff KingSep 23, 2011
  15. Michael HaggertySep 24, 2011
  16. Jeff KingSep 24, 2011
  17. Michael HaggertySep 24, 2011
  18. Junio C HamanoSep 26, 2011
  19. Michael HaggertySep 26, 2011
  20. Jeff KingSep 26, 2011
  21. Jakub NarebskiSep 26, 2011
  22. Michael HaggertySep 26, 2011
  23. Junio C HamanoSep 22, 2011
  24. Michael HaggertySep 23, 2011
  25. Stephen BashSep 23, 2011
  26. Michael HaggertySep 23, 2011
  27. Jakub NarebskiSep 22, 2011
  28. Michael HaggertySep 23, 2011
  29. Michael HaggertyFeb 17, 2012
  30. Junio C HamanoFeb 17, 2012
  31. Junio C HamanoFeb 17, 2012

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.