1

This is a similar issue I found: Make github use .gitattributes "binary" attribute If it's not intended to work in Github then my question applies to Gitlab only.


So the question: Imagine creating a branch with a single text Dockerfile and following .gitattributes:

[core]
    whitespace=trailing-space,space-before-tab
[apply]
    whitespace=fix
* binary
Dockerfile text=auto diff merge

You push this code, you can view commit in interface and it works just fine. Then you decide that Dockerfile should be binary as well (for whatever reason) and remove the last line. You commit it and then make change to the Dockerfile to check if it works. You call git show and it shows that changes indeed applied:

pzixe@ZPC MINGW64 ~/Documents/Repos/gitlab-test (all-binary)
$ git show HEAD
commit 141451116e292ae30a515920e6efb906f84b4142 (HEAD -> all-binary, origin/all-binary, github/all-binary)
Author: Psilon <pzixel@gmail.com>
Date:   Wed Apr 14 19:25:04 2021 +0300

    test changes

diff --git a/Dockerfile b/Dockerfile
index 11f0f66..fef4bc1 100644
Binary files a/Dockerfile and b/Dockerfile differ

But now if you check the github interface you will see that it actually shows a text diff instead of binary diff which was asked:

enter image description here

Then you're trying to see if GitLab is working differently and find out it's not:

enter image description here

So the question is: is there any way to make this working? I'd expect to see a text diff of initial commit 6c0745e and binary collapsed diff on latest commit 1414511

Here is a repo with reproduced case: https://github.com/Pzixel/test-gitlab

Alex Zhukovskiy
  • 9,565
  • 11
  • 75
  • 151

1 Answers1

0

Your .gitattributes file has invalid syntax and is probably being completely ignored on that basis. The first four lines (reproduced below) are configuration syntax and can't be included in a .gitattributes file. Configuration cannot be shipped as part of the repository and would need to either be stored in .git/config or in your personal .gitconfig.

[core]
    whitespace=trailing-space,space-before-tab
[apply]
    whitespace=fix

Beyond that, as outlined in this answer, GitHub doesn't use the binary attribute in .gitattributes to determine which files should be diffed. It will diff those files which appear to be plain text (and, by default, not autogenerated) and will not diff files which appear to be binary. You can mark a file as linguist-generated to indicate that it's a generated file, though.

I don't know if GitLab does or doesn't support this feature, but given that your .gitattributes file contains invalid syntax, that's probably not helping.

bk2204
  • 64,793
  • 6
  • 84
  • 100
  • Hmm, maybe you're right. This paragraph made me think that I actually can ship it: https://git-scm.com/docs/gitattributes#_end_of_line_conversion . You linked answer is what I've referenced in my question as well, so I've seen it but things could change in last 7 years. Thanks for reply I'l double check if gitattributes doesn't supprot this but I'm pretty sure that I recall this working even if it's not documented – Alex Zhukovskiy Apr 16 '21 at 10:46
  • I've just checked with valid `.gitattributes` file - it didn't work. Github just don't use `.gitattributes` but gitlab should (according to the docs). Going to ask there then. Thanks – Alex Zhukovskiy Apr 20 '21 at 18:35