threads / discuss / 40498

git diff --check in a bare repository

Subject: git diff --check in a bare repository

## tl;dr

One message between Oct 6, 2015 and Oct 6, 2015.

replies: 0people: 1as markdown or json

Andrei Neculau· Oct 6, 2015, 10:31 UTC · lore
Hello

I am using "git diff --check" on the "server-side" (i.e. in a bare repository as part of a git hook) with a .gitattributes rule saying

*.md text whitespace=-trailing-space # notice the - in front of trailing

I can check that the attribute is set/read correctly thanks to another thread on this mailing list

$ export GIT_INDEX_FILE=index.tmp $ git read-tree --reset -i $SHA $ git check-attr --cached foo.md # shows up whitespace: -trailing-space $ rm index.tmp

but then when I run
$ git diff --check $SHA^..$SHA -- foo.md

then I get an error that foo.md contains a trailing space (as if the .gitattributes in $SHA is ignored).

The reverse applies as well. Since trailing-space is enabled by default, I edited ~/.gitconfig and set core.whitespace = -trailing-space.

now "git diff --check" doesn't complain, but if I commit and push a rule in .gitattributes saying

*.md text whitespace=trailing-space
then I do not get an error when pushing foo.md with trailing-space.

I experience the same behaviour in 1.9.1 and 2.6.1. For what it's worth as input to the above issue, I have also tried

$ export GIT_INDEX_FILE=index.tmp $ git read-tree --reset -i $SHA $ git diff --check --cached -- foo.md

but the same behaviour can be noticed.
I am not subscribed to the mailing list, so please keep me in CC

Thank you in advance, Andrei

-- andreineculau.com

← back to recent threads