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.