commands: cross-platform log formatting to files #2178
Merged
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 pull request addresses the second and third points of #2076:
This one required some investigation. I originally thought that the goal here was to replace all instances of printing LF (
\n) characters sent to the terminal, but the actual fix is to just print platform-specific line ending sequences to files on disk, not the terminal.To determine this, I wrote two files to my
~/github/sharedirectory, which is accessible via my Windows VM. Each had the words "foo" and "bar". One was separated by a LF character, and the other by a CRLF, as follows:On Windows, they render in the terminal as expected independent of the line ending sequences (tested via cmd.exe, and reproducible in Git Bash):
So the fix in 43ec8e9 involved:
lineEndingargument to thelogPanicToWriter()func. This function is used to print to bothos.Stderr, as well as*os.Fileinstances, so it needs to be able to handle eitherLForCRLFs.gitLineEndingfunc, which prefers yourcore.autocrlfsetting, or defaults to the platform correct sequence instead.This is a larger problem with my (perhaps) excessive use of error-wrapping, but is easily solved by formatting errors with
%+vinstead of%s. Here's a before and after:%s(old):%+v(new):Closes: #2076.
/cc @git-lfs/core @JarrettR #2076