git-blame.nvim icon indicating copy to clipboard operation
git-blame.nvim copied to clipboard

Always getting "No Committed Yet" on Windows 10

Open LizardLiang opened this issue 1 year ago • 3 comments

Hi, I encountered this issue on my Windows 10 machine running Neovim (version details below):

NVIM v0.11.0-dev-1325+g30726c778c
Build type: RelWithDebInfo
LuaJIT 2.1.1732813678

Investigation revealed that the M.get_repo_root function was failing due to issues with the && operator. Instead of using cd to change the working directory, I resolved this by adding it to the cwd field in vim.fn.jobstart options:

-- git.lua
---@param callback fun(repo_root: string)
function M.get_repo_root(callback)
    if not utils.get_filepath() then
        return
    end
    local command = "git rev-parse --show-toplevel"

    utils.start_job(command, {
        on_stdout = function(data)
            callback(data[1])
        end,
    })
end

-- utils.lua
function M.start_job(cmd, opts)
       opts = opts or {}

    local jobstart_options = {
        stdout_buffered = true,
        ---@param data string[]
        on_stdout = function(_, data, _)
            if data and opts.on_stdout then
                opts.on_stdout(data)
            end
        end,
        on_exit = function(_, code, _)
            if opts.on_exit then
                opts.on_exit(code)
            end
        end,
    }

    if vim.fn.getftype(vim.fn.expand("%:p:h")) == "file" then
        jobstart_options.cwd = vim.fn.expand("%:p:h")
    end

    local id = vim.fn.jobstart(cmd, jobstart_options)

    if opts.input then
        vim.fn.chansend(id, opts.input)
        vim.fn.chanclose(id, "stdin")
    end

    return id
end

This modification seems to resolve the issue

LizardLiang avatar Dec 10 '24 06:12 LizardLiang

I believe this issue is not limited to Windows 10. Currently on MacOS (Sonoma 14.5) with Nvim version below and seeing the same problem happen

NVIM v0.10.1 Build type: Release LuaJIT 2.1.1720049189

jordansmith28 avatar Dec 10 '24 23:12 jordansmith28

@LizardLiang 's solution worked for me, but only after a tweak: Change

jobstart_options.cwd = vim.fn.expand("%:p:h")

to

jobstart_options.cwd = vim.fn.shellescape(vim.fn.expand("%:p:h"))

wolterhv avatar Mar 25 '25 14:03 wolterhv

similar for me, neovim 0.11.4, Linux (various distros)

miekg avatar Nov 06 '25 10:11 miekg