Description
Problem
This PR fixed #2076 but it appears that the functionality has regressed. When cargo writes a lock file, it appears to use LF line endings rather than matching the existing line endings as I would expect.
The test for the above PR writes out a file with CRLFs and then runs generate-lockfile and expects the content on disk to be unchanged. Unfortunately, generate-lockfile tests to see if the lines are equal (which is line-ending agnostic) before writing anything out and so doesn't actually re-write the file. If you edit the test to defeat this optimization then it fails because the lock file is written out with LFs only.
Steps
- Check out a rust project on Windows with the (default) git setting of autocrlf = true.
- Note that line endings of your cargo.lock file are CRLF. (
git ls-files --eol
is a convenient way to do this) - Run
cargo add $SOMETHING
- Note that line endings have changed to LF.
- Try committing the lock file; this will fail if you have the (default) git setting of safecrlf = true
Possible Solution(s)
We could re-establish a check in write_pkg_lockfile
to detect and match line endings, as was done in the original PR linked above. I'd be happy to take a crack at this if that sounds good.
Notes
If helpful, git version says: git version 2.41.0.windows.3
.
Version
cargo 1.73.0
release: 1.73.0
host: x86_64-pc-windows-msvc
libgit2: 1.6.4 (sys:0.17.2 vendored)
libcurl: 8.2.1-DEV (sys:0.4.65+curl-8.2.1 vendored ssl:Schannel)
os: Windows 10.0.22621 (Windows 11 Enterprise) [64-bit]