Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Gutter diff adapts to git's core.autocrlf setting#3909

Open
MiguelRoldao wants to merge 1 commit intomicro-editor:master from
MiguelRoldao:win-diff
Open

Gutter diff adapts to git's core.autocrlf setting #3909
MiguelRoldao wants to merge 1 commit intomicro-editor:master from
MiguelRoldao:win-diff

Conversation

@MiguelRoldao
Copy link

@MiguelRoldao MiguelRoldao commented Nov 11, 2025
edited
Loading

Using micro on windows is very annoying, since the diff gutter will be filled with "modified", on git versioned files.

The diff in micro is calculated between the last commit in the repository and the active workspace. However, if the option core.autocrlf is enabled on windows, if the file in the repo has LF line endings, the file in the workspace will have CR LF line endings. Resulting in a detectable modification in every line of the file.

My solution checks if core.autocrlf is enabled. If it's not, if processes the diff normally. If it is enabled, the diff is calculated using git cat-file --filters, to filter out the line end changes.

This PR should solve issue #1517

Copy link
Author

This could possibly be simplified to a single:

shell.ExecCommand("git", "-C", dirName, "cat-file", "--filters", "HEAD:./" .. fileName)

But I'm not fluent in git to the extent of being able to guarantee that this would be equivalent to git show in all other cases.

Comment on lines -13 to +22
local diffBase, err = shell.ExecCommand("git", "-C", dirName, "show", "HEAD:./" .. fileName)

local autocrlf, err = shell.ExecCommand("git", "-C", dirName, "config", "get", "core.autocrlf")

local diffBase
if not err and string.match(autocrlf, "true") then
diffBase, err = shell.ExecCommand("git", "-C", dirName, "cat-file", "--filters", "HEAD:./" .. fileName)
else
diffBase, err = shell.ExecCommand("git", "-C", dirName, "show", "HEAD:./" .. fileName)
end

Copy link
Contributor

@Neko-Box-Coder Neko-Box-Coder Dec 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just use

diffBase, err = shell.ExecCommand("git", "-C", dirName, "cat-file", "--filters", "HEAD:./" .. fileName)

regardless of autocrlf?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer

@Neko-Box-Coder Neko-Box-Coder Neko-Box-Coder left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /