Skip to content

Cargo always uses LF line endings for Cargo.lock even if CRLF were present #12897

Open
@jder

Description

@jder

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

  1. Check out a rust project on Windows with the (default) git setting of autocrlf = true.
  2. Note that line endings of your cargo.lock file are CRLF. (git ls-files --eol is a convenient way to do this)
  3. Run cargo add $SOMETHING
  4. Note that line endings have changed to LF.
  5. 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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lockfileArea: Cargo.lock issuesC-bugCategory: bugE-easyExperience: EasyS-needs-infoStatus: Needs more info, such as a reproduction or more background for a feature request.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions