-
-
Notifications
You must be signed in to change notification settings - Fork 624
fix(git): git watcher showing error for bare repositories #1819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,37 @@ local log = require "nvim-tree.log" | |
|
||
local has_cygpath = vim.fn.executable "cygpath" == 1 | ||
|
||
function M.get_absolutegitdir(cwd) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as mentioned, I think this should partially replace |
||
local ps = log.profile_start("git absolutegitdir %s", cwd) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you. |
||
|
||
local cmd = { "git", "-C", cwd, "rev-parse", "--absolute-git-dir" } | ||
log.line("git", "%s", vim.inspect(cmd)) | ||
|
||
local absolutegitdir = vim.fn.system(cmd) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can return different errors, what's the plan for handling them? maybe check if the result is a valid dir? |
||
|
||
log.raw("git", absolutegitdir) | ||
log.profile_end(ps, "git absolutegitdir %s", cwd) | ||
|
||
if vim.v.shell_error ~= 0 or not absolutegitdir or #absolutegitdir == 0 or absolutegitdir:match "fatal" then | ||
return nil | ||
end | ||
|
||
-- git always returns path with forward slashes | ||
if vim.fn.has "win32" == 1 then | ||
-- msys2 git support | ||
if has_cygpath then | ||
absolutegitdir = vim.fn.system("cygpath -w " .. vim.fn.shellescape(absolutegitdir)) | ||
if vim.v.shell_error ~= 0 then | ||
return nil | ||
end | ||
end | ||
absolutegitdir = absolutegitdir:gsub("/", "\\") | ||
end | ||
|
||
-- remove newline | ||
return absolutegitdir:sub(0, -2) | ||
end | ||
|
||
function M.get_toplevel(cwd) | ||
local ps = log.profile_start("git toplevel %s", cwd) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will break existing behavior since
get_project_root()
has a few more checksnvim-tree.lua/lua/nvim-tree/git/init.lua
Lines 72 to 76 in cf90837
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#1809 will be merged shortly, with some significant refactoring in this area.
We must merge master before testing this PR.