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

Newline at end of file is not shown #779

Closed
przepompownia opened this issue Mar 31, 2023 · 9 comments · Fixed by #862
Closed

Newline at end of file is not shown #779

przepompownia opened this issue Mar 31, 2023 · 9 comments · Fixed by #862
Labels
bug Something isn't working upstream issue Issue/limitation of Neovim core

Comments

@przepompownia
Copy link

przepompownia commented Mar 31, 2023

Description

Gitsigns seems to not detect newlines appended at the end of file.

Neovim version

NVIM v0.9.0-dev-1305+g83bfd94d1

Operating system and version

Debian Sid

Expected behavior

Detect bottom newline, show on signs and hunk window.

Actual behavior

No information about bottom newline fro mGisigns.

Minimal config

vim.o.packpath = '/tmp/nvim/site'

local plugins = {
  gitsigns = 'https://github.com/lewis6991/gitsigns.nvim',
  -- ADD OTHER PLUGINS _NECESSARY_ TO REPRODUCE THE ISSUE
}

for name, url in pairs(plugins) do
  local install_path = '/tmp/nvim/site/pack/test/start/'..name
  if vim.fn.isdirectory(install_path) == 0 then
    vim.fn.system { 'git', 'clone', '--depth=1', url, install_path }
  end
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. In an existing repo add some file without a newline at the end, commit the changes, append a newline e.g. in bash
echo -n x >|bar
git add bar
git commit -m 'add bar' bar
echo -ne '\n' >>bar
  1. Look at the change (GIT_PAGER= git diff) before opening nvim:
diff --git a/bar b/bar
index ba0e162..5716ca5 100644
--- a/bar
+++ b/bar
@@ -1 +1 @@
-bar
\ No newline at end of file
+bar
  1. Run nvim --clean -u minimal.lua bar
  2. Inside run Gitsigns get_hunks (try also pewview_hunk).

Gitsigns debug messages

signs.init: Using vimfn signs                                                                                                                                                                                                           
dprintf: Deriving GitSignsAdd from DiffAdd
dprintf: Deriving GitSignsChange from DiffChange
dprintf: Deriving GitSignsDelete from DiffDelete
dprintf: Deriving GitSignsChangedelete from GitSignsChange
dprintf: Deriving GitSignsTopdelete from GitSignsDelete
dprintf: Deriving GitSignsUntracked from GitSignsAdd
dprintf: Deriving GitSignsAddNr from GitSignsAdd
dprintf: Deriving GitSignsChangeNr from GitSignsChange
dprintf: Deriving GitSignsDeleteNr from GitSignsDelete
dprintf: Deriving GitSignsChangedeleteNr from GitSignsChangeNr
dprintf: Deriving GitSignsTopdeleteNr from GitSignsDeleteNr
dprintf: Deriving GitSignsUntrackedNr from GitSignsAddNr
dprintf: Deriving GitSignsAddLn from DiffAdd
dprintf: Deriving GitSignsChangeLn from DiffChange
dprintf: Deriving GitSignsChangedeleteLn from GitSignsChangeLn
dprintf: Deriving GitSignsUntrackedLn from GitSignsAddLn
dprintf: Deriving GitSignsStagedAdd from GitSignsAdd
dprintf: Deriving GitSignsStagedChange from GitSignsChange
dprintf: Deriving GitSignsStagedDelete from GitSignsDelete
dprintf: Deriving GitSignsStagedChangedelete from GitSignsChangedelete
dprintf: Deriving GitSignsStagedTopdelete from GitSignsTopdelete
dprintf: Deriving GitSignsStagedAddNr from GitSignsAddNr
dprintf: Deriving GitSignsStagedChangeNr from GitSignsChangeNr
dprintf: Deriving GitSignsStagedDeleteNr from GitSignsDeleteNr
dprintf: Deriving GitSignsStagedChangedeleteNr from GitSignsChangedeleteNr
dprintf: Deriving GitSignsStagedTopdeleteNr from GitSignsTopdeleteNr
dprintf: Deriving GitSignsStagedAddLn from GitSignsAddLn
dprintf: Deriving GitSignsStagedChangeLn from GitSignsChangeLn
dprintf: Could not derive GitSignsStagedDeleteLn
dprintf: Deriving GitSignsStagedChangedeleteLn from GitSignsChangedeleteLn
dprintf: Could not derive GitSignsStagedTopdeleteLn
dprintf: Deriving GitSignsAddPreview from DiffAdd
dprintf: Deriving GitSignsDeletePreview from DiffDelete
dprintf: Deriving GitSignsCurrentLineBlame from NonText
dprintf: Deriving GitSignsAddInline from TermCursor
dprintf: Deriving GitSignsDeleteInline from TermCursor
dprintf: Deriving GitSignsChangeInline from TermCursor
dprintf: Deriving GitSignsAddLnInline from GitSignsAddInline
dprintf: Deriving GitSignsChangeLnInline from GitSignsChangeInline
dprintf: Deriving GitSignsDeleteLnInline from GitSignsDeleteInline
dprintf: Deriving GitSignsDeleteVirtLn from DiffDelete
dprintf: Deriving GitSignsDeleteVirtLnInLine from GitSignsDeleteLnInline
attach(1): Attaching (trigger=setup
run_job: git --version
run_job: git --no-pager --literal-pathspecs -c gc.auto=0 config user.name
run_job: git --no-pager --literal-pathspecs -c gc.auto=0 rev-parse --show-toplevel --absolute-git-dir --abbrev-ref HEAD
run_job: git --no-pager --literal-pathspecs -c gc.auto=0 --git-dir /tmp/x/.git -c core.quotepath=off ls-files --stage --others --exclude-standard --eol /tmp/x/bar
watch_gitdir(1): Watching git dir
run_job: git --no-pager --literal-pathspecs -c gc.auto=0 --git-dir /tmp/x/.git show :0:bar
update(1): updates: 1, jobs: 5
cli.run: Running action 'get_hunks' with arguments {}
update(1): updates: 2, jobs: 5
update(1): updates: 3, jobs: 5
update(1): updates: 4, jobs: 5
cli.run: Running action 'get_hunks' with arguments {}
update(1): updates: 5, jobs: 5
cli.run: Running action 'preview_hunk' with arguments {}
@przepompownia przepompownia added the bug Something isn't working label Mar 31, 2023
@lewis6991
Copy link
Owner

I think this might be a limitation of Neovim, since buffers always include a newline at the end.

There are options endofline and fixendofline options.

- Vim normally appends an <EOL> at the end of the file if there is none.
  Setting the 'binary' option prevents this.  If you want to add the final
  <EOL>, set the 'endofline' option.  You can also read the value of this
  option to see if there was an <EOL> for the last line (you cannot see this
  in the text).

So apparently you can detect <EOL> by looking at 'endofline', however this doesn't appear to work.

I tested with Vim 9 and it does work. So this could be a bug in Neovim.

@lewis6991 lewis6991 added the upstream issue Issue/limitation of Neovim core label Aug 25, 2023
@lewis6991
Copy link
Owner

Raised neovim/neovim#24869

lewis6991 added a commit that referenced this issue Aug 25, 2023
lewis6991 added a commit that referenced this issue Aug 25, 2023
lewis6991 added a commit that referenced this issue Aug 25, 2023
lewis6991 added a commit that referenced this issue Aug 25, 2023
lewis6991 added a commit that referenced this issue Aug 25, 2023
@Subjective
Copy link

Hi, it seems like after #862, running :Gitsigns reset_buffer now adds a new line to the end of the buffer.

@lewis6991
Copy link
Owner

Is there a hunk in the buffer before you do this?

@Subjective
Copy link

Subjective commented Aug 25, 2023

Is there a hunk in the buffer before you do this?

No, it happens regardless of whether there is a hunk or not.
Screen Recording 2023-08-25 at 1 09 47 PM

@lewis6991
Copy link
Owner

Ok, I can see the cause of the problem. Thanks for reporting.

@lewis6991 lewis6991 reopened this Aug 25, 2023
@przepompownia
Copy link
Author

image

@lewis6991 thanks for #862 Now I see the missing sign.

It would be good to fix displaying the details to show what really happens (as opposed to the image above).

@lewis6991
Copy link
Owner

I think git has a special message for no newline at end of file. We can probably do the same.

@lewis6991
Copy link
Owner

#863 fixes reset_buffer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working upstream issue Issue/limitation of Neovim core
Projects
None yet
3 participants