Closed DecimalTurn closed 1 year ago
Hi @DecimalTurn, This is very cool! Was actually looking initially to see if this could be done with github actions, but never knew about these git filters. Do you know if it also works with github desktop etc?
Do you know if it also works with github desktop etc?
I just tested with GitHub Desktop to commit a .bas file with LF line endings and it did perform the conversion during the staging process.
Was actually looking initially to see if this could be done with github actions
It might still be good to use GitHub Actions to be sure no LF-only files sneaks in when a contributor forgets to add the .gitconfig file to their local configs.
@sancarn - Even if the git filter works, it creates a bit of overhead when committing which starts to be perceptible with large VBA repos. For that reason, I've decided to make a GitHub Action (Enforce-CRLF) and ran it successfully on my fork (logs).
If you are interested in using it, let me know and I can make a PR to add it and remove the mentions of git filter.
@DecimalTurn That would be great thanks, I was thinking an action would be a good idea also when I initially came across this issue, thanks for developing 👍 Would love a PR
Currently, the README states that contributors should "Ensure lines end in
\r\n
and not\n
only". However, there are currently some inconsistencies in the repo with certain files using\n
(LF) only.With this PR, I'm adding a Git filter for
.bas
,.frm
and.cls
files, so that the conversion to\r\n
(CRLF) is automatic. This filter is applied to files via the.gitattributes
. I'm using-text
which tells Git to stop its usual behavior for text file (converting to LF) and we add the filtercrlf
.For the filter to be enabled on your machine, simply run
git config include.path ../.gitconfig
(while insde the repo). This will add the common.gitconfig
to your localCONFIG
file and give it access to thecrlf
filter definition. The definition is quite simple: it's using the commandunix2dos
to make the conversion. That command comes with Git-for-Windows and is usually available by default on the main Linux distributions.I've also taken the opportunity to put in place a default normalization to LF for other files in the repo with an exception for
.ahk
files. This is optional, but it's generally good practice for GitHub projects. If you deem this approach unsuitable for this repo, I can always revert the commits related to that change.Note that most of the changes in this PR are line renormalizations. You can confirm that by adding
?w=1
to the url of the Files changed tab. The real changes that would need review are located in these files: