Conversation
Previously, patches would be generated for hunks the user wanted to stage with lines concatenated by either: - a specific platform line ending (currently only Windows) if no file exists at the path the hunk came from, or; - reading the file and determining the line endings of the file by checking the line ending of the first line, only. While both of these worked for entirely new files and / or on platforms where the environment default line ending is the same as the indexed file's line endings, it would clobber the indexed file's line endings when the environment's default line endings differed from the index. The reason why this only clobbers the indexed files line endings is because the patch is eventually applied only to the index, not the working copy. This would result in the entire file being considered changed in the diff without additional options to filter out the noise. This usually only affects Windows due to it using `CRLF` by default, and only when you work on a repository that primarily commits in `LF` line endings, but could've probably affected it in the reverse if it was also vice-versa, with the system being in `LF` while the repository was in `CRLF`, a setup typical for Windows-specific code repositories being contributed to cross-platform by developers on other platforms. (NOTE: I say probably since I haven't had a chance to test that specific reverse scenario yet, I'm only working off of the core line ending mismatch problem) This patch fixes the problem by leveraging Git to determine the existing indexed file's line endings and using those to concatenate the patch's lines with, falling back to the existing logic if the file isn't currently in the repository's index OR if the file has mixed line endings. This keeps the line endings consistent as to what would be written to the repository index on commits.
This was an erroneous change where the variable was used even though the value returned from `git ls-files --eol` doesn't include the leading slash. Using the "constant" doesn't actually perform the match correctly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(This fixes #2011)
Previously, patches would be generated for hunks the user wanted to stage with lines concatenated by either:
While both of these worked for entirely new files and / or on platforms where the environment default line ending is the same as the indexed file's line endings, it would clobber the indexed file's line endings when the environment's default line endings differed from the index.
The reason why this only clobbers the indexed files line endings is because the patch is eventually applied only to the index, not the working copy.
This would result in the entire file being considered changed in the diff without additional options to filter out the noise.
This usually only affects Windows due to it using
CRLFby default, and only when you work on a repository that primarily commits inLFline endings, but could've probably affected it in the reverse if it was also vice-versa, with the system being inLFwhile the repository was inCRLF, a setup typical for Windows-specific code repositories being contributed to cross-platform by developers on other platforms.(NOTE: I say probably since I haven't had a chance to test that specific reverse scenario yet, I'm only working off of the core line ending mismatch problem)
This patch fixes the problem by leveraging Git to determine the existing indexed file's line endings and using those to concatenate the patch's lines with, falling back to the existing logic if the file isn't currently in the repository's index OR if the file has mixed line endings.
This keeps the line endings consistent as to what would be written to the repository index on commits.
This is one possible solution to the problem, one I've been using locally on my Windows machine to great effect.