I have a .strings file that git interprets as binary by default, but I want everyone on my team to see the diff on GitLab when I create a pull request.
As per documentation, I’m able to see the diff locally when I add *.strings diff=Localizable
to .gitattributes and this textconv driver to .git/config:
[diff "Localizable"]
textconv = "iconv -f utf-16 -t utf-8"
binary = false
The problem is, we don’t commit the .git/config file, so everyone would have to add this to their config file and we still wouldn’t be able to see the diff while reviewing code on GitLab. Is there a way to define textconv in a file that’s safe to commit? I tried adding it to .gitattributes instead but it did nothing.
In case it matters, this is an Xcode project.
2
Answers
No.
This is unfortunate, but it’s also necessary for security, because if you could define a
textconv
filter in a file that did get committed, a bad actor could define a fake filter that (while maybe doing some textconv-ing) acted as a Trojan horse, for instance.What you can do is provide a script that sets this up for users, and tell them inspect the script if you like, and then if you trust it, run it to set things up. (Make the script as simple as you can so that people can inspect it first, though you might want to have it look to see if it’s already been run and not do anything in that case.)
As torek mentioned, specifying textconv is not practical for security reasons. The best that you might be able to do is add a
.gitattributes
file in the root of your repository that declares this as text (like*.strings text=true
) rather than binary. This should at least help you see the diffs in GitLab.You need to commit your
.gitattributes
file to the default branch (e.g.master
ormain
) of the project before it will have any effect. Changes to.gitattributes
files in any other branches will have no effect on how diffs are viewed in the GitLab UI.You must also commit the
.gitattributes
file with UTF-8 encodings for it to work, per the gitlab documentation