Skip to content

feat: support custom $GIT_DIR #2263

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

Merged
merged 3 commits into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lua/nvim-tree/explorer/watch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@ local M = {
}

local function is_git(path)
return vim.fn.fnamemodify(path, ":t") == ".git"
-- If $GIT_DIR is set, consider its value to be equivalent to '.git'.
-- Expand $GIT_DIR (and `path`) to a full path (see :help filename-modifiers), since
-- it's possible to set it to a relative path. We want to make our best
-- effort to expand that to a valid absolute path.
if vim.fn.fnamemodify(path, ":p") == vim.fn.fnamemodify(vim.env.GIT_DIR, ":p") then
return true
elseif vim.fn.fnamemodify(path, ":t") == ".git" then
return true
else
return false
end
end

local IGNORED_PATHS = {
Expand Down
3 changes: 2 additions & 1 deletion lua/nvim-tree/git/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ function M.load_project_status(cwd)
end)
end

watcher = Watcher:new(utils.path_join { project_root, ".git" }, WATCHED_FILES, callback, {
local git_dir = vim.env.GIT_DIR or utils.path_join { project_root, ".git" }
watcher = Watcher:new(git_dir, WATCHED_FILES, callback, {
project_root = project_root,
})
end
Expand Down