lewis6991 / gitsigns.nvim

Git integration for buffers
MIT License
4.86k stars 186 forks source link

CRLF and charset utf-8-bom #1068

Closed seblj closed 2 months ago

seblj commented 2 months ago

Description

On work, we are using an editorconfig with the following content:

[*]
charset = utf-8-bom
end_of_line = crlf

as we have a lot of developers using windows.

However, I am using macOS, and I am having some issues with gitsigns marking every line as changed. Maybe I am doing something wrong.

I tried to set core.autocrlf to different values, and none of them seems to change anything.

Neovim version

NVIM v0.11.0-dev-283+gfe5d1279a

Operating system and version

macOS 14.5 (23F79)

Expected behavior

I would expect it to not show any changes, as I haven't done any changes to the file.

Actual behavior

It shows that all lines are changed like this: image

Also, trying to view the diff in a popup with :Gitsigns preview_hunk, this happens: image

Minimal config

for name, url in pairs{
  gitsigns = 'https://github.com/lewis6991/gitsigns.nvim',
  -- ADD OTHER PLUGINS _NECESSARY_ TO REPRODUCE THE ISSUE
} do
local install_path = vim.fn.fnamemodify('gitsigns_issue/'..name, ':p')
if vim.fn.isdirectory(install_path) == 0 then
vim.fn.system { 'git', 'clone', '--depth=1', url, install_path }
end
vim.opt.runtimepath:append(install_path)
end

require('gitsigns').setup{
  debug_mode = true, -- You must add this to enable debug messages
  -- ADD GITSIGNS CONFIG THAT IS _NECESSARY_ FOR REPRODUCING THE ISSUE
}

-- ADD INIT.LUA SETTINGS THAT IS _NECESSARY_ FOR REPRODUCING THE ISSUE

Steps to reproduce

  1. Create a file with some content with LF line endings. Doesn't matter.

  2. Paste this into a .editorconfig:

    [*]
    charset = utf-8-bom
    end_of_line = crlf
  3. Open the file again and notice it shows all lines as diffed.

Gitsigns debug messages

22.87 D attach(1): Attaching (trigger=BufReadPost)                                                                                                                                          
23.00 D run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 config user.name                                                                                       
44.16 D run_job: git --version                                                                                                                                                              
56.32 D run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 rev-parse --show-toplevel --absolute-git-dir --abbrev-ref HEAD                                         
67.76 D run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir /Users/sebastian/bom-test/.git -c core.quotepath=off ls-files --stage --others --exclude-stan
dard --eol /Users/sebastian/bom-test/foo.lua                                                                                                                                                
81.29 D watch_gitdir(1): Watching git dir  

(Also a lot of deriving colors which doesn't seem relevant)



### Gitsigns cache

_No response_
seblj commented 2 months ago

I think this was just me who was stupid🤦‍♂️ I see that I have to run this for it to work properly:

git rm -rf --cached .
git reset --hard HEAD