fix(#1976): support non-standard $GIT_DIR (#2012)

* Improve $GIT_DIR handling

- Retrieve $GIT_DIR using `git rev-parse --absolute-git-dir`
- Move $GIT_DIR ignore in the project exploration part

Resolves #1976

* Code review

- move norm_path to utils.lua
- fix comment #2012

* add comments for utils.norm_path

* get_git_directory use norm_path from utils

* watcher improvements

---------

Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
Damien Mehala
2023-04-22 05:26:43 +02:00
committed by GitHub
parent f8bb6b4c76
commit 517dee64c1
4 changed files with 82 additions and 38 deletions

View File

@@ -5,10 +5,11 @@ local M = {
debouncers = {},
}
local has_cygpath = vim.fn.executable "cygpath" == 1
M.is_unix = vim.fn.has "unix" == 1
M.is_macos = vim.fn.has "mac" == 1 or vim.fn.has "macunix" == 1
M.is_wsl = vim.fn.has "wsl" == 1
-- false for WSL
M.is_windows = vim.fn.has "win32" == 1 or vim.fn.has "win32unix" == 1
function M.str_find(haystack, needle)
@@ -38,6 +39,26 @@ function M.path_split(path)
return path:gmatch("[^" .. path_separator .. "]+" .. path_separator .. "?")
end
--- Normalise a path:
--- windows: replace slashes with backslashes
--- cygwin: resolve path first via cygpath
--- @param path string
--- @return string|nil nil on cygpath failure
function M.norm_path(path)
if M.is_windows then
-- msys2 git support
if has_cygpath then
path = vim.fn.system("cygpath -w " .. vim.fn.shellescape(path))
if vim.v.shell_error ~= 0 then
return nil
end
end
path = path:gsub("/", "\\")
end
return path
end
---Get the basename of the given path.
---@param path string
---@return string