Skip to content

fix: keep CRLF line endings when staging or discarding lines - #3053

Open
jayhemnani9910 wants to merge 1 commit into
gitui-org:masterfrom
jayhemnani9910:fix/line-staging-keep-crlf
Open

jayhemnani9910 wants to merge 1 commit into
gitui-org:masterfrom
jayhemnani9910:fix/line-staging-keep-crlf

Conversation

@jayhemnani9910

Copy link
Copy Markdown

This Pull Request fixes line staging and line discard in files with CRLF line endings.

In a file stored with CRLF (no autocrlf), staging or discarding a single line rewrites every other line to LF:

committed:  "a\r\nb\r\nc\r\n"
worktree:   "a\r\nb\r\nc\r\nX\r\n"
discard X   -> "a\nb\nc\r\n"            (expected "a\r\nb\r\nc\r\n")
stage X     -> index "a\nb\nc\r\nX\r\n"  (expected "a\r\nb\r\nc\r\nX\r\n")

The next commit then changes the line endings of the whole file, and a discard leaves the working file changed everywhere.

It changes the following:

  • stage_lines and discard_lines split the old content with split_terminator('\n') instead of lines(), which also strips \r. Hunk lines already keep their \r, so the rebuilt content keeps the file's own endings.
  • changelog entry

I followed the checklist:

  • I added unittests (test_stage_keeps_crlf, test_discard_keeps_crlf; both fail without the change)
  • I ran make check without errors (ran its fmt, clippy and test steps, not sort/deny; test_pre_commit_py fails here with or without the change because there is no python binary)
  • I tested the overall application
  • I added an appropriate item to the changelog

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.

1 participant