Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: respect current EOL in gitignore #329

Merged
merged 6 commits into from
Jun 5, 2024
Merged

Conversation

cristiand391
Copy link
Member

@cristiand391 cristiand391 commented May 22, 2024

Fixes: #301

Problem:
sf-install reads the .gitignore in the project and tries to split the content by \n (even on windows).
This messes up your gitignore if it uses CRLF (most common on windows but can happen on linux/mac too) like in the linked issue above.

dev-scripts now will detect the EOL used by the local file and use that for parsing the content and final write.
We can't use node's os.EOL because it assumes unix === LF and win === CRLF.

same change in sf-clean

NOTE:
there's a file check done here to see if the .gitignore in the project matches the template:

const copied = copyFile(gitignoreSourcePath, gitignoreTargetPath);

https://github.com/forcedotcom/dev-scripts/blob/e2efc93a4af12dc5953d1beb673cc768a7e620a6/utils/standardize-files.js#L35C1-L48C2

isDifferent just normalizes line endings for comparision so that's left as is.

Testing

  1. clone plugin-info (or any other of our plugins)
  2. make .gitignore use CRLF (open in vscode click on LF at the bottom of the screen, choose CRLF and save the file
    Screenshot 2024-06-04 at 5 01 56 PM

sf-install

now run yarn (will run sf-install), it'll print standardizing config files for plugin-info and if you open the file you'll see it's missing the CLEAN ALL items and other stuff.

sf-clean

restore changes (clean git status), redo step 1 & 2 and run yarn clean, will print:

➜  plugin-info git:(main) ✗ yarn clean
yarn run v1.22.19
$ sf-clean
,oclif.lockfest.json

but the gitignore have more stuff in it that's missing because of CRLF.

install the prerelease in this branch and the steps above should work wether gitignore uses LF or CRLF on any os.

@W-15748612@

@cristiand391 cristiand391 marked this pull request as ready for review June 4, 2024 18:19
@cristiand391 cristiand391 requested a review from a team as a code owner June 4, 2024 18:19
@cristiand391 cristiand391 changed the title fix: normalize line endings fix: respect current EOL in gitignore Jun 4, 2024
@mdonnalley
Copy link
Contributor

QA

🟢 line endings are preserved on sf-install when using LF
🟢 line endings are preserved on sf-install when using CRLF
🟢 line endings are preserved on sf-clean when using LF
🟢 line endings are preserved on sf-clean when using CRLF

@mdonnalley mdonnalley merged commit ace3484 into main Jun 5, 2024
9 checks passed
@mdonnalley mdonnalley deleted the prerelease/line-endings branch June 5, 2024 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

gitignore standardization does not work on CRLF file endings
3 participants