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

bug: loading fugitive with cmd = "Git" throws error when passed multiple arguments #659

Closed
3 tasks done
garcia5 opened this issue Mar 16, 2023 · 1 comment · Fixed by #660
Closed
3 tasks done
Labels
bug Something isn't working

Comments

@garcia5
Copy link

garcia5 commented Mar 16, 2023

Did you check docs and existing issues?

  • I have read all the lazy.nvim docs
  • I have searched the existing issues of lazy.nvim
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

v0.9.0-dev-1167+gddd257f75-dirty

Operating system/version

MacOS 13.2.1

Describe the bug

When configuring the tpope/vim-fugitive plugin to lazy-load on the :Git command, I get an error when passing more than 1 argument. This looks like it's caused by passing event.fargs as the args property to vim.cmd here, while fugitive (and maybe others?) are expecting { event.args }

Current behavior:
:Git restore % -> vim.cmd({ cmd = "Git", args = { "restore", "%" } ->

Error executing Lua callback: .../share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:32: Wrong number of arguments                                                                                                                                                                                                                                                                     
stack traceback:
        [C]: in function 'cmd'
        .../share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:32: in function <.../share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:16>

Running the command a 2nd time after the error appears works as expected

Steps To Reproduce

  1. Add plugin
{
"tpope/vim-fugitive",
cmd = "Git"
}
  1. :Git status --short
  2. Error message appears

Expected Behavior

Fugitive command should execute first try without error. I'm not sure if event.fargs should be changed to { event.args } in cmd.lua, since maybe other plugins work differently. But maybe a config could be added for the cmd field to specify combining arguments?

e.g.

-- plugins/git.lua
return {
  "tpope/vim-fugitive",
  cmd = {
    "Git",
    {
      combine_args = true, -- false by default to keep existing behavior
    }
  }
}

### Repro

```Lua
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
	vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
	vim.fn.system({
		"git",
		"clone",
		"--filter=blob:none",
		"--single-branch",
		"https://github.com/folke/lazy.nvim.git",
		lazypath,
	})
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
	-- do not remove the colorscheme!
	"folke/tokyonight.nvim",
	-- add any other pugins here
	{
		"tpope/vim-fugitive",
		cmd = "Git",
	},
}
require("lazy").setup(plugins, {
	root = root .. "/plugins",
})

-- add anything else here
vim.opt.termguicolors = true
-- do not remove the colorscheme!
vim.cmd([[colorscheme tokyonight]])
@garcia5 garcia5 added the bug Something isn't working label Mar 16, 2023
@folke folke closed this as completed in efe36bd Mar 16, 2023
@folke
Copy link
Owner

folke commented Mar 16, 2023

Should be fixed now. Thank you for the detailed bug report!

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