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: Error when using git rm #475

Closed
3 tasks done
caoculus opened this issue Sep 6, 2024 · 1 comment
Closed
3 tasks done

bug: Error when using git rm #475

caoculus opened this issue Sep 6, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@caoculus
Copy link

caoculus commented Sep 6, 2024

Did you check the docs and existing issues?

  • I have read the docs
  • I have searched the existing issues

Neovim version (nvim -v)

0.10.1

Operating system/version

NixOS 24.11

Describe the bug

When git file operations are enabled, I get this error when I try to remove a file from within Oil:

Error executing luv callback:
...n/Downloads/test/.repro/plugins/oil.nvim/lua/oil/git.lua:54: E5560: Vimscript function must not be called in a lua loop callback
stack traceback:
        [C]: in function 'jobstart'
        ...n/Downloads/test/.repro/plugins/oil.nvim/lua/oil/git.lua:54: in function 'rm'
        .../test/.repro/plugins/oil.nvim/lua/oil/adapters/files.lua:559: in function <.../test/.repro/plugins/oil.nvim/lua/oil/adapters/files.lua:557>

After pressing ENTER, deletion gets stuck at this loading bar...

image

...and if I press "Cancel", then the file still gets deleted.

I took a look at "adapters/files.lua" and I see that the callback for git add is wrapped in vim.schedule_wrap, while the callback for git rm is not:

if config.git.rm(path) then
local old_cb = cb
cb = function(err)
if not err then
git.rm(path, old_cb)
else
old_cb(err)
end
end
end

If I manually add vim.schedule_wrap then this seems to fix the issue.

Thanks in advance!

What is the severity of this bug?

minor (annoyance)

Steps To Reproduce

  1. Create an empty git repository (say, in the "test" folder).
  2. nvim -u repro.lua
  3. Open Oil in the git repository.
  4. Create "a.txt" using Oil.
  5. Delete "a.txt" using Oil.

Expected Behavior

The file should be deleted without any error.

Directory structure

test/a.txt

Repro

-- save as repro.lua
-- run with nvim -u repro.lua
-- DO NOT change the paths
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "runtime", "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 = {
    "folke/tokyonight.nvim",
    {
        "stevearc/oil.nvim",
        config = function()
            require("oil").setup({
                -- enable git file operations (this is the only change)
                git = {
                    add = function() return true end,
                    mv = function() return true end,
                    rm = function() return true end,
                }
            })
        end,
    },
    -- add any other plugins here
}
require("lazy").setup(plugins, {
    root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

Did you check the bug with a clean config?

  • I have confirmed that the bug reproduces with nvim -u repro.lua using the repro.lua file above.
@caoculus caoculus added the bug Something isn't working label Sep 6, 2024
@stevearc
Copy link
Owner

Should be fixed. Thanks for the 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

No branches or pull requests

2 participants