On Thu, 5 May 2016 08:28:43 -0700 (PDT)
Jack Poon <j...@atcipher.com> wrote:

> We are working on an add-on over git using git filters, and testing
> other tools that encapsulate Git.
> 
> For some reason, git reports that there is difference for any
> zero-byte when git filters are used.
> 
> Is this a feature or bug?  What's the suggested workaround?

I can't verify this with Git 2.1.4 on a Debian Jessie running amd64.

Here's an annotated transcript of the sample session I've just
performed.  It creates a repository, configures a filter which
merely runs `/bin/cat` both for clean and smudge actions (hence
it performs what CS PhDs would call an "identity transformation"),
sets up a .gitattributes file which applies this filter to the files
matching the "*.txt" pattern, adds two zero-length files in two
adjacent commits and verifies the diff looks as expected.

Then we force checking out of these files and try again.

% git --version
git version 2.1.4

~% cd /tmp
tmp% git init filters
Initialized empty Git repository in /tmp/filters/.git/
tmp% cd filters
filters% git config --add --local filter.foo.smudge '/bin/cat'
filters% git config --add --local filter.foo.clean '/bin/cat'
filters% cat >.gitattributes
*.txt   filter=foo
filters% touch aaa.txt
filters% stat -c %s aaa.txt 
0
filters% git add aaa.txt
filters% git commit -m 'Add aaa.txt'
[master (root-commit) bec42c4] Add aaa.txt
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 aaa.txt
filters% touch bbb.txt
filters% stat -c %s bbb.txt 
0
filters% git add bbb.txt
filters% git commit -m 'Add bbb.txt'
[master 5c30813] Add bbb.txt
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 bbb.txt
filters% git diff --name-status HEAD~1 HEAD
A       bbb.txt

Observe that the diff output looks as expected: a single file
has been added.

Now let's force checking out these files to make them pass
through the smudge filter:

filters% rm aaa.txt bbb.txt 
filters% GIT_TRACE=1 git checkout -f -- .
20:45:08.515779 git.c:349               trace: built-in: git 'checkout'
'-f' '--' '.'
20:45:08.516375 run-command.c:341       trace: run_command: '/bin/cat'
20:45:08.516607 run-command.c:192       trace: exec: '/bin/cat'
20:45:08.517432 run-command.c:341       trace: run_command: '/bin/cat'
20:45:08.517633 run-command.c:192       trace: exec: '/bin/cat'

filters%  git diff --name-status HEAD~1 HEAD
A       bbb.txt

Again, the diff looks OK.

Let's diff to the index:

filters% git diff --staged
filters% 


Hence my take on your issue is that either you have a bug in your
filter code or a bug in Git (less likely).

I'd first try to debug this a little bug further.  Use GIT_TRACE
to verify what gets called on `git add` and `git checkout`.
Use `git ls-tree` and `git cat-file` to get hold onto individual
raw blobs representing the contents of the files in the repository,
verify they are really of size zero etc.

Also make sure you don't have execution bit flips on your files:
while Git does not track permission bits, it does track execution
bit and whether the file is a symlink or not.

If all will fail, contact the main Git list, but this time, please
be sure to include all the relevant details about the system you're
observing this on -- starting with the Git version.  See [1] for
more info.

1. https://gist.github.com/tfnico/4441562

-- 
You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to