Problem/Motivation
From .gitattributes:
# Auto-detect text files, ensure they use LF.
* text=auto eol=lf
This line is wrecking havoc when adding themes or dependencies that contain binary files with CRLF line endings, such as font files (*.ttf). I just spent a couple of hours debugging an error I was getting in a custom theme for D8. The error was: "warning: CRLF will be replaced by LF in foobar.ttf". Removing that line from .gitattributes made the error go away.
To reproduce:
- add this line to composer.json:
"symfony/console": "2.6.*@dev",
- composer update
- git add core/vendor/symfony/console/
- warning: CRLF will be replaced by LF in core/vendor/symfony/console/Symfony/Component/Console/Resources/bin/hiddeninput.exe.
The file will have its original line endings in your working directory.
At the moment, we set a general rule that all files in git should use LF line endings, except for a handful of binary extension that we define at the end of .gitattributes. We shouldn't dictate how people should manage any possible file extension in git, we should only enforce the "Auto-detect text files, ensure they use LF." rules on the files that we know belong to Drupal. Having such a rule for all files is not going to scale for joe the developer (that was me today) who is using a theme that happens to include binary files that have the extension *.foobar and have CRLF line endings.
Proposed resolution
Remove the general rule for all extension, and only list the files we know should be versioned in Git (the way we have it now just below the * rule). As a result, we can remove the list of exceptions at the end of .gitattributes.
Remaining tasks
patch
User interface changes
n/a
API changes
n/a
Comment | File | Size | Author |
---|---|---|---|
#40 | test.sh_.txt | 1.37 KB | toomanypets |
#26 | 2333243-26.patch | 3.29 KB | alexpott |
#8 | gitattributes-relax-auto-rule-2333243.patch | 667 bytes | kenorb |
Comments
Comment #1
scor CreditAttribution: scor commentedComment #2
scor CreditAttribution: scor commentedComment #3
Iztok CreditAttribution: Iztok commentedYes, and there are many other file types out there - like video files (where I found the issue).
I also commented out line 20 to fix this.
Comment #4
dawehnerTwo points:
Comment #5
ultimikeWe hit a related issue with a D8 Migrate in Core patch (#2410623) that includes a .gz file (of a D6 mysql dump). I was able to create and apply the patch locally, but the d.o. test bot couldn't apply it cleanly. chx figured out that it was the fact that the patch was created using a normal "diff" for the binary file which was the root of the problem. We solved this issue by adding a .gitattributes file to the proper directory with:
d6.gz -text -diff
This makes it so there is no diff text for the d6.gz file, instead a binary diff is included in the patch.
It is my understanding that in some cases spaces and line breaks that mess with binary diffs, rendering them problematic.
Here is the issue and patch: https://www.drupal.org/node/2410623#comment-9566443
-mike
Comment #6
neclimdul#2498515: Update additional Symfony Components to 2.7.0 changed the console .exe file but this is still a bit of an issue.
Comment #7
kenorb CreditAttribution: kenorb commentedSome git clients wrongly detect some files as in text format. This includes DOC files, and many other binaries, therefore corrupting them.
Example of such file: https://github.com/ruflin/Elastica/blob/master/test/data/test.doc
Related:
- http://stackoverflow.com/questions/18536863/git-refuses-to-reset-discard...
- http://stackoverflow.com/questions/15958446/sourcetree-app-says-uncommit...
Comment #8
kenorb CreditAttribution: kenorb commentedComment #9
ztl8702 CreditAttribution: ztl8702 commentedActually even .JPG, .jpeg, etc are mistakenly treated as text files.
This could cause damage of data.
I am using git 2.1.4 on Ubuntu 15.04.
Comment #10
kenorb CreditAttribution: kenorb commented@ztl8702 I had issues with images as well. If you could please test the patch and see if that helps.
Comment #11
swentel CreditAttribution: swentel commentedThis is really not critical
Comment #12
ztl8702 CreditAttribution: ztl8702 commented@kenorb yes it works.
I think as long as we remove
* text=auto eol=lf
it should no longer corrupt binary files.But the problem then is will some file types that were supposed to be auto-detected be missed?
Comment #13
ztl8702 CreditAttribution: ztl8702 commentedThis issue should be moved to the newest dev version now.
Comment #14
ztl8702 CreditAttribution: ztl8702 commentedComment #15
Jon@s CreditAttribution: Jon@s commentedJust wanted to add that instead of removing the line
* text=auto eol=lf
You can just add the other file types to the end of the file (these lines):
Had to do that with a bunch of font file types.
Comment #16
tstoecklerLooks good to me.
Comment #17
ztl8702 CreditAttribution: ztl8702 commented@Jon@s
Be aware that capitalization does matter.
.JPG
.jPG
.jpg
and.jPg
etc. need seperate lines, and we cannot gurantee which one will be for user uploaded files. Base on my testing, Drupal will not change the file extensition to lower case if the user uploads something like "photo.JPG".Therefore I suggest we stick to the patch on #8.
Comment #18
Jon@s CreditAttribution: Jon@s commented@ztl8702
True, but without
* text=auto eol=lf
you now have to go and explicitly name every text file type, which is many more than binary file types and chances are a new file type is a text format. Also while capitalization matters, .JPG .jPg and the like should never appear anyways (although especially .JPG was common on older Microsoft system).Comment #19
alexpottHere's a list of extensions of all files in the git repository...
I think at the very least we need to ensure all of these are present and correct. Many of the odder ones come from the htaccess test.
Comment #20
kenorb CreditAttribution: kenorb commented@alexpott This could be list of extensions on specific repository, but it doesn't guarantee that the rules won't corrupt any other file formats which are part of theme or modules. Such as project/module documents (docx), spreadsheets (xlsx), fonts (woff). The list can be endless.
Comment #21
alexpott@kenorb I agree with removing the rule - I just think we need to cover all the extensions that are included in core.
Comment #22
kenorb CreditAttribution: kenorb commentedThe issue is about bug report where file are being corrupted, because of current version of .gitattributes. Listing all file extensions from the core to implement additional rules sounds like a separate feature request.
Comment #23
alexpott@kenorb nope - removing the rule affects all of these files.
Comment #24
mlncn CreditAttribution: mlncn at Agaric for MASS Design Group commentedI was frustrated by Drupal's apparently .gitattributes overriding my own (globally and a level up in the repository) without knowing what was going wrong. If this approach stays we should at least add a couple more font files to the "this is not text please stop breaking everything" list:
Comment #25
kenorb CreditAttribution: kenorb commentedSome people say (at least 3) that using
text=auto
andeol=lf
at the same time is misleading and both options contradict each other, sinceeol
option disables automatic detection of text files, in other wordseol=lf
effectively setstext
. I'm not sure if that's valid claim. Any comments?Comment #26
alexpottAdditionally I've removed .info and .test as we no longer have files with these extensions.
Comment #27
rootworkI would back up @mlncn's suggestion in #24 that we add those font-file extensions. I've run into that a bunch of times with theming.
Comment #28
alexpott@rootwork if we do #26 then we don't need to as
Will mean that fonts will no longer be treated as text.
Comment #29
rootworkOh I get it now. Sorry for being dense!
Comment #30
joelpittetLooks like this is on target now. Thanks for helping get this straight
Comment #32
alexpottUnrelated test fail.
Comment #34
joelpittetComment #35
kenorb CreditAttribution: kenorb commentedRe #25, see: EOL conversion on checkout for text files only and What will `* text=auto eol=lf` in gitattributes do? which makes text=auto and eol=lf invalid combination as it is currently (not a patch).
Comment #36
xjmThe current patch does not seem to implement this part of the proposed resolution. However, I think this is fine -- being explicit is better to make sure we do not corrupt files. #26 seems comprehensive for me.
I think #24 is also already addressed by the current patch and anything else can be a followup. I think #4 in particular is potentially worth followups.
Since this file is in the root of the Drupal site and could override user customizations, I think it is best to commit to 8.2.x only to avoid disruptions. We typically warn people when we change such configuration files in release notes, so tagging for that.
Comment #38
toomanypets CreditAttribution: toomanypets commented@alexpott -- #26 does not address #24. I've tested. In order to treat .eot, .woff, and .woff2 files as binary, they must be explicitly listed in .gitattributes. I'm reopening #2711855: Add binary font file types to .gitattributes.
Comment #39
alexpott@toomanypets can you detail how you tested so I can repeat the test?
Comment #40
toomanypets CreditAttribution: toomanypets commented@alexpott This is how I tested...
$ drush dl drupal-8.2.x --drupal-project-rename=drupal-8.2.x-2333243
$ cd drupal-8.2.x-2333243
$ curl https://fonts.gstatic.com/s/roboto/v15/CWB0XYA8bzo0kSThX0UTuA.woff2 --create-dirs -o themes/junk/fonts/Roboto.woff2
$ git init -q && git add -A && git commit -q -m "Initial commit."
$ truncate -s +10 themes/junk/fonts/Roboto.woff2
$ git add -A && git commit -q -m "Added 10 bytes to the end of Roboto.woff2"
$ git diff HEAD^ HEAD
The resulting diff simply indicates that the files differ -- this is not the desired behavior with binary files.
$ echo "*.woff2 -text diff" >> .gitattributes
$ git diff HEAD^ HEAD
The resulting diff is correct.
I've attached a bash script if you'd prefer to do it the easy way.