* 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:
@@ -1,7 +1,6 @@
|
||||
local M = {}
|
||||
local log = require "nvim-tree.log"
|
||||
|
||||
local has_cygpath = vim.fn.executable "cygpath" == 1
|
||||
local utils = require "nvim-tree.utils"
|
||||
|
||||
function M.get_toplevel(cwd)
|
||||
local profile = log.profile_start("git toplevel %s", cwd)
|
||||
@@ -18,16 +17,9 @@ function M.get_toplevel(cwd)
|
||||
return nil
|
||||
end
|
||||
|
||||
-- git always returns path with forward slashes
|
||||
if vim.fn.has "win32" == 1 then
|
||||
-- msys2 git support
|
||||
if has_cygpath then
|
||||
toplevel = vim.fn.system("cygpath -w " .. vim.fn.shellescape(toplevel))
|
||||
if vim.v.shell_error ~= 0 then
|
||||
return nil
|
||||
end
|
||||
end
|
||||
toplevel = toplevel:gsub("/", "\\")
|
||||
toplevel = utils.norm_path(toplevel)
|
||||
if toplevel == nil then
|
||||
return nil
|
||||
end
|
||||
|
||||
-- remove newline
|
||||
@@ -94,4 +86,28 @@ function M.file_status_to_dir_status(status, cwd)
|
||||
return r
|
||||
end
|
||||
|
||||
function M.get_git_directory(cwd)
|
||||
local profile = log.profile_start("git directory %s", cwd)
|
||||
|
||||
local cmd = { "git", "-C", cwd, "rev-parse", "--absolute-git-dir" }
|
||||
log.line("git", vim.inspect(cmd))
|
||||
|
||||
local git_dir = vim.fn.system(cmd)
|
||||
|
||||
log.raw("git", git_dir)
|
||||
log.profile_end(profile)
|
||||
|
||||
if vim.v.shell_error ~= 0 or not git_dir or #git_dir == 0 or git_dir:match "fatal" then
|
||||
return nil
|
||||
end
|
||||
|
||||
git_dir = utils.norm_path(git_dir)
|
||||
if git_dir == nil then
|
||||
return nil
|
||||
end
|
||||
|
||||
-- remove newline
|
||||
return git_dir:sub(0, -2)
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user