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

Error after update – gitsigns: Ignoring invalid configuration field 'on_attach_pre' #965

Closed
PhilippFeO opened this issue Apr 2, 2024 · 8 comments · Fixed by #1002
Closed
Labels
bug Something isn't working

Comments

@PhilippFeO
Copy link

Description

After Executing :Lazy sync, I receive the following error message when starting Neovim: gitsigns: Ignoring invalid configuration field 'on_attach_pre' (s. attached screenshot), although I am not using this field anywhere.

I've seen in the changes of the last commit that some things concerning yadm changed but I was not able to fix it myself. I also checked the help on yadm. It refers to using on_attach_pre instead but since the error message states the field is invalid, I am cueless.

Neovim version

NVIM v0.9.5 Build type: Release LuaJIT 2.1.1692716794

Operating system and version

Ubunut 22.04 LTS

Expected behavior

Neovim starts without printing an error message.

Actual behavior

Neovim starts and prints an error message although the mentioned field is not used anywhere.

Error message using my config:
Screenshot from 2024-04-02 09-08-31

Error message with minimal.lua:
Screenshot from 2024-04-02 09-27-56

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
  signs               = {
    -- Colors may be changed via the according highlight groupd, check :h gitsigns-highlight-groups
    add          = { text = '+' },
    change       = { text = '~' },
    delete       = { text = '󰧧' },
    topdelete    = { text = '󰆴' },
    changedelete = { text = '~' },
    untracked    = { text = '' },
  },
  signcolumn          = true,  -- Toggle with `:Gitsigns toggle_signs`
  -- different highlight options
  numhl               = false, -- Toggle with `:Gitsigns toggle_numhl`
  linehl              = false, -- Toggle with `:Gitsigns toggle_linehl`
  word_diff           = false, -- Toggle with `:Gitsigns toggle_word_diff`
  -- Watch changes
  watch_gitdir        = {
    enable = true,
    interval = 1000,
    follow_files = true
  },
  attach_to_untracked = true,
  -- Virtual text with information about the commit where it originates
  -- current_line_blame = true, -- Toggle with `:Gitsigns toggle_current_line_blame`
  -- current_line_blame_opts = {
  --   virt_text = true,
  --   virt_text_pos = 'eol', -- 'eol' | 'overlay' | 'right_align'
  --   delay = 1000,
  --   ignore_whitespace = false,
  -- },
  -- current_line_blame_formatter = '<author>, <author_time:%Y-%m-%d> - <summary>',
  sign_priority       = 6,     -- should be below LSP signs
  update_debounce     = 100,
  status_formatter    = nil,   -- Use default
  max_file_length     = 40000, -- Disable if file is longer than this (in lines)
  preview_config      = {
    -- Options passed to nvim_open_win
    border = 'single',
    style = 'minimal',
    relative = 'cursor',
    row = 0,
    col = 1
  },
  yadm                = {
    enable = false
  },
}

Steps to reproduce

  1. nvim --clean -u minimal.lua
  2. Start Neovim

Gitsigns debug messages

:Gitsigns debug_messages

run_job: git --version
run_job: git --no-pager --literal-pathspecs -c gc.auto=0 rev-parse --show-toplevel --absolute-git-dir --abbrev-ref HEAD
cli.run: Running action 'debug_messages' with arguments {}

Gitsigns dump_cache

{}
@PhilippFeO PhilippFeO added the bug Something isn't working label Apr 2, 2024
@PhilippFeO
Copy link
Author

Removing

yadm = { 
 enable = false
}

solves the issue. I found it by trial and error. An error message indicating a solution or a more verbose commit message would have improved removing the error message. The help on yadm pointing to gitsigns-config-on_attach_pre but this term doesn't show up in the help at all.

To be honest, I don't know what yadm is about. I use(d) kickstart.nvim and should not have touched gitsigns. Maybe it is completely obvious for people who know yadm.

skyuplam added a commit to skyuplam/nixos-config that referenced this issue Apr 2, 2024
@lewis6991
Copy link
Owner

If you don't use yadm, then why on earth did you configure it in gitsigns?

I strongly suggest you remove any configuration that repeats the defaults since you'll see this issue again. The more config you have, the more likely you are to have issues when config changes.

@PhilippFeO
Copy link
Author

I use(d) it, because it was part of kickstart.nvim. For me, the point of kickstart.nvim is that I don't have to iterate over every plugin before using it – very handy when starting with Neovim.

@lewis6991
Copy link
Owner

lewis6991 commented Apr 2, 2024

kickstart.nvim should not be setting fields which are already default.

EDIT: not on master https://github.com/nvim-lua/kickstart.nvim/blob/19afab164183a5e80d8f7e7ae9df6b57e26a4a48/init.lua#L243-L259

@PhilippFeO

This comment was marked as abuse.

lewis6991 added a commit that referenced this issue Apr 2, 2024
@DrKJeff16
Copy link

It's Back (6ef8c54)

I have debugged all my config after followed your instructions regarding yadm, yet the warning keeps popping up:

Screenshot_20240404_124759_Termux.png

This only appeared after updating. At first I thought it was an error concerning a fault in my code (there was, but it was unrelated). After debugging and fixing it, the same warning has kept popping up thus far.

I'll provide a sample of my configuration, but bear in mind I'm using customized modules for handling some stuff. Still, I've documented all the bits I've deemed relevant. If anything else is needed from my config please tell me.

--- ...
local Gsig = require('gitsigns')

---@type UserBufModeKeys
local keys = {
	n = {
		-- Navigati7on
		{ lhs = '<leader>G]c', rhs = "&diff ? ']c' : '<CMD>Gitsigns next_hunk<CR>'", opts = { expr = true } },
		{ lhs = '<leader>G[c', rhs = "&diff ? '[c' : '<CMD>Gitsigns prev_hunk<CR>'", opts = { expr = true } },

		-- Actions
		{ lhs = '<leader>Ghs', rhs = ':Gitsigns stage_hunk<CR>' },
		{ lhs = '<leader>Ghr', rhs = ':Gitsigns reset_hunk<CR>' },
		{ lhs = '<leader>GhS', rhs = '<CMD>Gitsigns stage_buffer<CR>' },
		{ lhs = '<leader>Ghu', rhs = '<CMD>Gitsigns undo_stage_hunk<CR>' },
		{ lhs = '<leader>GhR', rhs = '<CMD>Gitsigns reset_buffer<CR>' },
		{ lhs = '<leader>Ghp', rhs = '<CMD>Gitsigns preview_hunk<CR>' },
		{ lhs = '<leader>Ghb', rhs = '<CMD>lua require"gitsigns".blame_line{full=true}<CR>' },
		{ lhs = '<leader>Gtb', rhs = '<CMD>Gitsigns toggle_current_line_blame<CR>' },
		{ lhs = '<leader>Ghd', rhs = '<CMD>Gitsigns diffthis<CR>' },
		{ lhs = '<leader>GhD', rhs = '<CMD>lua require"gitsigns".diffthis("~")<CR>' },
		{ lhs = '<leader>Gtd', rhs = '<CMD>Gitsigns toggle_deleted<CR>' },
	},
	v = {
		{ lhs = '<leader>Ghs', rhs = ':Gitsigns stage_hunk<CR>' },
		{ lhs = '<leader>Ghr', rhs = ':Gitsigns reset_hunk<CR>' },
	},
}

---@alias GitSignOpts { ['text']: string }

---@class GitSigns
---@field add GitSignOpts
---@field change GitSignOpts
---@field delete GitSignOpts
---@field topdelete GitSignOpts
---@field changedelete GitSignOpts
---@field untracked GitSignOpts

---@alias GitSignsArr GitSigns[]

---@type GitSigns
local signs = {
	add          = { text = '÷' },
	change       = { text = '~' },
	delete       = { text = '-' },
	topdelete    = { text = 'X' },
	changedelete = { text = '' },
	untracked    = { text = '' },
}

Gsig.setup({
	---@param bufnr integer
	on_attach = function(bufnr)
		for mode, v in next, keys do
			---@type BufMapFunction
			local func = bufmap[mode]

			for _, t in next, v do
				func(bufnr, t.lhs, t.rhs, t.opts or {})
			end
		end
	end,

	signs = signs,

	signcolumn = true,  -- Toggle with `:Gitsigns toggle_signs`
	numhl      = true, -- Toggle with `:Gitsigns toggle_numhl`
	linehl     = false, -- Toggle with `:Gitsigns toggle_linehl`
	word_diff  = false, -- Toggle with `:Gitsigns toggle_word_diff`
	watch_gitdir = { follow_files = true },
	auto_attach = true,
	attach_to_untracked = true,
	current_line_blame = false, -- Toggle with `:Gitsigns toggle_current_line_blame`
	current_line_blame_opts = {
		virt_text = false,
		virt_text_pos = 'eol', -- 'eol' | 'overlay' | 'right_align'
		delay = 5000,
		ignore_whitespace = false,
		virt_text_priority = 100,
	},
	current_line_blame_formatter = '<author>, <author_time:%Y-%m-%d> - <summary>',
	sign_priority = 4,
	update_debounce = 100,
	-- status_formatter = nil, -- Use default
	max_file_length = 40000, -- Disable if file is longer than this (in lines)
	preview_config = {
		border = 'double',
		style = 'minimal',
		relative = 'cursor',
		row = 0,
		col = 1,
	},

	-- WARN: This causes a VERY annoying warning
	--		 each time Neovim starts.
	--		 See: [https://github.com/lewis6991/gitsigns.nvim/issues/965](this issue).
	-- yadm = { enable = false },
})
--- ...

@lewis6991
Copy link
Owner

You know the commit you referenced is 4 months old?

@DrKJeff16
Copy link

Welp, a bit of an awkward oversight from my part. Either way, thanks for your time, and apologies for taking it up.

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
3 participants