neogit icon indicating copy to clipboard operation
neogit copied to clipboard

Failed to detect git repo under windows

Open ray-x opened this issue 2 years ago • 3 comments

Description

The issue I see now is different. It may releated to https://github.com/NeogitOrg/neogit/issues/469 But after updating the plugin the error message is slightly different. ATM, I am promoted I need to Initialize a repository in my working folder where .git exists. I never see this message on Mac/Linux

Neovim version

It existed in both 0.9.4 release and nightly

Operating system and version

Windows + Powershell

Steps to reproduce

Open a file inside a git repo with neovim and start Neogit. The neogit is complaining it is not a git repo. Seems somewhere in the code interpreting the folder to C:/xxx/xxx while it should be C:\xxx\xxx under windows.

Expected behavior

Neogit should recognize current working folder is a git repo

Actual behavior

Git repo not recognized.

Minimal config

-- NOTE: See the end of this file if you are reporting an issue, etc. Ignore all the "scary" functions up top, those are
-- used for setup and other operations.
local M = {}

local base_root_path = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":p:h") .. "/.min"
function M.root(path)
  return base_root_path .. "/" .. (path or "")
end

function M.load_plugin(plugin_name, plugin_url)
  local package_root = M.root("plugins/")
  local install_destination = package_root .. plugin_name
  vim.opt.runtimepath:append(install_destination)

  if not vim.loop.fs_stat(package_root) then
    vim.fn.mkdir(package_root, "p")
  end

  if not vim.loop.fs_stat(install_destination) then
    print(string.format("> Downloading plugin '%s' to '%s'", plugin_name, install_destination))
    vim.fn.system({
      "git",
      "clone",
      "--depth=1",
      plugin_url,
      install_destination,
    })
    if vim.v.shell_error > 0 then
      error(string.format("> Failed to clone plugin: '%s' in '%s'!", plugin_name, install_destination),
        vim.log.levels.ERROR)
    end
  end
end

---@alias PluginName string The plugin name, will be used as part of the git clone destination
---@alias PluginUrl string The git url at which a plugin is located, can be a path. See https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols for details
---@alias MinPlugins table<PluginName, PluginUrl>

---Do the initial setup. Downloads plugins, ensures the minimal init does not pollute the filesystem by keeping
---everything self contained to the CWD of the minimal init file. Run prior to running tests, reproducing issues, etc.
---@param plugins? table<PluginName, PluginUrl>
function M.setup(plugins)
  vim.opt.packpath = {}                      -- Empty the package path so we use only the plugins specified
  vim.opt.runtimepath:append(M.root(".min")) -- Ensure the runtime detects the root min dir

  -- Install required plugins
  if plugins ~= nil then
    for plugin_name, plugin_url in pairs(plugins) do
      M.load_plugin(plugin_name, plugin_url)
    end
  end

  vim.env.XDG_CONFIG_HOME = M.root("xdg/config")
  vim.env.XDG_DATA_HOME = M.root("xdg/data")
  vim.env.XDG_STATE_HOME = M.root("xdg/state")
  vim.env.XDG_CACHE_HOME = M.root("xdg/cache")

  -- NOTE: Cleanup the xdg cache on exit so new runs of the minimal init doesn't share any previous state, e.g. shada
  vim.api.nvim_create_autocmd("VimLeave", {
    callback = function()
      vim.fn.system({
        "rm",
        "-r",
        "-f",
        M.root("xdg")
      })
    end
  })
end

-- NOTE: If you have additional plugins you need to install to reproduce your issue, include them in the plugins
-- table within the setup call below.
M.setup({
  plenary = "https://github.com/nvim-lua/plenary.nvim.git",
  telescope = "https://github.com/nvim-telescope/telescope.nvim",
  diffview = "https://github.com/sindrets/diffview.nvim",
  neogit = "https://github.com/NeogitOrg/neogit"
})
-- WARN: Do all plugin setup, test runs, reproductions, etc. AFTER calling setup with a list of plugins!
-- Basically, do all that stuff AFTER this line.
require("neogit").setup({}) -- For instance, setup Neogit

ray-x avatar Nov 18 '23 12:11 ray-x

I can't seem to reproduce this. When you talk about promoting, are you talking about launching neovim from an administrative shell in windows?

rawlingsr avatar Nov 18 '23 19:11 rawlingsr

image I'm using windows powershell

simplely printout require("neogit.lib.git.cli").git_root() and you should see the difference.

ray-x avatar Nov 18 '23 23:11 ray-x

@rawlingsr I experience this same issue, every repository. Powershell 7 latest and Windows Terminal. Lazygit and other utilities do not have the same issue. For some reason it can't seem to get the working directory. Lazyvim config has the issuel; However, when I tried nvchad it did not and possibly kickstart if that helps. Thanks. I may try it on wsl or linux vm and see if it is Lazyvim distro related.

AddictArts avatar Apr 15 '24 22:04 AddictArts

This problem was driving me crazy since I love Neogit's workflow (keeps me in the "zone"), but I kept getting prompted whenever doing git operations on windows machines (regardless of powershell, bash, terminal, or wezterm). PR #1281 should fix it.

cjgibbons avatar May 06 '24 19:05 cjgibbons

I put a note asking about why the PR is held up when time permits by the maintainer. It would be great to get it merged.

AddictArts avatar May 07 '24 16:05 AddictArts

@AddictArts if you setup neovim to pull neogit temporarily from 'cjgibbons/neogit' you can test out the fix. This is the only change I have in that branch. I think I'm still seeing some bugginess related to other issues like changing/renaming files and then trying to open them, also it changes the nature of Issue #1140. But hopefully this fix helps to narrow down the others.

cjgibbons avatar May 07 '24 17:05 cjgibbons

If anyone can verify the issue is gone under windows/powershell with latest version. Feel free to confirm so the issue can be closed. I do not own Windows laptop to verify it now.

ray-x avatar May 09 '24 23:05 ray-x

@ray-x confirmed, thank you so much @cjgibbons and @ray-x

So nice to have it back.

AddictArts avatar May 10 '24 15:05 AddictArts

Thanks!

ray-x avatar May 11 '24 01:05 ray-x