Skip to content

Always getting "No Committed Yet" on Windows 10 #147

@LizardLiang

Description

@LizardLiang

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions