From 847b012670b20a885645b106596be6f4260674e0 Mon Sep 17 00:00:00 2001 From: Zach Himsel Date: Sat, 10 Jun 2023 09:41:11 -0400 Subject: [PATCH 1/3] 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. --- lua/nvim-tree/git/init.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lua/nvim-tree/git/init.lua b/lua/nvim-tree/git/init.lua index 2714e39ee57..4a7277798b5 100644 --- a/lua/nvim-tree/git/init.lua +++ b/lua/nvim-tree/git/init.lua @@ -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 From 1d5d4a8c40c0c887ce4e37fd1a9ed13753bf7f58 Mon Sep 17 00:00:00 2001 From: Zach Himsel Date: Thu, 6 Jul 2023 14:50:47 -0400 Subject: [PATCH 2/3] 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`. --- lua/nvim-tree/explorer/watch.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lua/nvim-tree/explorer/watch.lua b/lua/nvim-tree/explorer/watch.lua index dad1738c4f5..097ee51faf6 100644 --- a/lua/nvim-tree/explorer/watch.lua +++ b/lua/nvim-tree/explorer/watch.lua @@ -8,7 +8,14 @@ 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' + if path == vim.env.GIT_DIR then + return true + elseif vim.fn.fnamemodify(path, ":t") == ".git" then + return true + else + return false + end end local IGNORED_PATHS = { From 56dbad22af90278a79a33bd2130a5c7c1e4d05c6 Mon Sep 17 00:00:00 2001 From: Zach Himsel Date: Thu, 6 Jul 2023 14:54:01 -0400 Subject: [PATCH 3/3] fix: Attempt to make a relative $GIT_DIR absolute --- lua/nvim-tree/explorer/watch.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lua/nvim-tree/explorer/watch.lua b/lua/nvim-tree/explorer/watch.lua index 097ee51faf6..cbebe3b144b 100644 --- a/lua/nvim-tree/explorer/watch.lua +++ b/lua/nvim-tree/explorer/watch.lua @@ -8,8 +8,11 @@ local M = { } local function is_git(path) - -- If $GIT_DIR is set, consider its value to be equivalent to '.git' - if path == vim.env.GIT_DIR then + -- 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