Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

^M not stripped off in Windows #927

Closed
aloknigam247 opened this issue Dec 11, 2023 · 5 comments · Fixed by #928
Closed

^M not stripped off in Windows #927

aloknigam247 opened this issue Dec 11, 2023 · 5 comments · Fixed by #928
Labels
bug Something isn't working

Comments

@aloknigam247
Copy link

Description

I am using neovim in windows and in Gitsigns diffthis ^M is not stripped off from the buffer.
I have debugged the code and found that the check fails here
https://github.com/lewis6991/gitsigns.nvim/blob/6e05045fb1a4845fe44f5c54aafe024444c422ba/lua/gitsigns/util.lua#L199C5-L199C35

Somehow lines read from git have a extra entry in array which is empty and for the last item in the array this check fails as #xs0[i] is 0.

I fixed this case locally by adding the check as

    if #xs0[i] > 0 and xs0[i]:sub(-1) ~= '\r' then

I am not sure if this location is correct for fix.

Neovim version

NVIM v0.10.0-dev-1801+g2ebd328a7

Operating system and version

Windows

Expected behavior

^M should be stripped off in windows.
image

Actual behavior

^M remains if the buffer which makes Gitsigns diffthis command not useful.
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. nvim --clean -u minimal.lua
  2. Open any file in WIndows which have some git diff
  3. Gitsigns diffthis

Gitsigns debug messages

No response

@aloknigam247 aloknigam247 added the bug Something isn't working label Dec 11, 2023
@aloknigam247
Copy link
Author

I find similar issue in other commands too like when I enable toggle_deleted text has ^M.
image

@lewis6991
Copy link
Owner

Can you provide a minimal example file that causes this? What do the CRLF line endings look like? Is CR (\r) omitted for consecutive LF (\n).

@aloknigam247
Copy link
Author

aloknigam247 commented Dec 12, 2023

This issue is common on all the files I have in my git repo.
Reproducible for my README as well.
image

What do the CRLF line endings look like

The issue is not in checked out file but the file fetched by gitsigns. This needs a strip off which is skipped for an empty line which did existed in original file. If this extra line wasn't added by gitsigns then util.strip_cr() works fine.

@lewis6991
Copy link
Owner

lewis6991 commented Dec 12, 2023

Reproducible for my README as well.

Not reproducible for me.

image

The issue is not in checked out file but the file fetched by gitsigns. This needs a strip off which is skipped for an empty line which did existed in original file. If this extra line wasn't added by gitsigns then util.strip_cr() works fine.

Yes, I'm aware, but the checked in file is still a file.

Can you answer my original question please and show me how the CRLF's are arranged in a minimal file.

I don't have a windows machine so I can't easily find this out.

@lewis6991
Copy link
Owner

I am able to reproduce by doing set ff=dos and committing the file.

lewis6991 added a commit that referenced this issue Dec 12, 2023
When scanning for CRLF do not check EOF.

Fixes #927
lewis6991 added a commit that referenced this issue Dec 12, 2023
When scanning for CRLF do not check EOF.

Fixes #927, #835
lewis6991 added a commit that referenced this issue Dec 12, 2023
When scanning for CRLF do not check EOF.

Fixes #927, #835
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants