feat: support custom $GIT_DIR (#2263)
* feat: Watch $GIT_DIR for git changes, if set While rarely used, it's possible to set the $GIT_DIR environment variable to instruct git to use a directory other than `.git`. This checks if that environment variable is set; if it is, the plugin will watch that directory. If it's not set, it'll fall back to the default `.git` directory. * fix: Don't create two watchers for $GIT_DIR This will ignore a path for watching if EITHER it's '.git', or the value of $GIT_DIR (if it's set). If $GIT_DIR is not set, the vim.env object returns `nil`, which will never match `path`. * fix: Attempt to make a relative $GIT_DIR absolute
This commit is contained in:
@@ -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 = {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user