Skip to content

Commit 1f5bbc1

Browse files
committed
Revert "fix(#1976): support non-standard $GIT_DIR (#2012)"
This reverts commit 517dee6.
1 parent bb375fb commit 1f5bbc1

File tree

4 files changed

+38
-82
lines changed

4 files changed

+38
-82
lines changed

lua/nvim-tree/explorer/watch.lua

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,25 @@ local Watcher = require("nvim-tree.watcher").Watcher
44

55
local M = {}
66

7-
M.ignore_dirs = {
7+
local function is_git(path)
8+
return vim.fn.fnamemodify(path, ":t") == ".git"
9+
end
10+
11+
local IGNORED_PATHS = {
812
-- disable watchers on kernel filesystems
913
-- which have a lot of unwanted events
1014
"/sys",
1115
"/proc",
1216
"/dev",
1317
}
1418

15-
function M.ignore_dir(path)
16-
table.insert(M.ignore_dirs, path)
17-
end
18-
1919
local function is_folder_ignored(path)
20+
for _, folder in ipairs(IGNORED_PATHS) do
21+
if vim.startswith(path, folder) then
22+
return true
23+
end
24+
end
25+
2026
for _, ignore_dir in ipairs(M.ignore_dirs) do
2127
if vim.fn.match(path, ignore_dir) ~= -1 then
2228
return true
@@ -38,7 +44,7 @@ function M.create_watcher(node)
3844
path = node.absolute_path
3945
end
4046

41-
if is_folder_ignored(path) then
47+
if is_git(path) or is_folder_ignored(path) then
4248
return nil
4349
end
4450

@@ -68,7 +74,7 @@ end
6874
function M.setup(opts)
6975
M.enabled = opts.filesystem_watchers.enable
7076
M.debounce_delay = opts.filesystem_watchers.debounce_delay
71-
M.ignore_dirs = vim.tbl_extend("force", M.ignore_dirs, opts.filesystem_watchers.ignore_dirs)
77+
M.ignore_dirs = opts.filesystem_watchers.ignore_dirs
7278
M.uid = 0
7379
end
7480

lua/nvim-tree/git/init.lua

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ local log = require "nvim-tree.log"
22
local utils = require "nvim-tree.utils"
33
local git_utils = require "nvim-tree.git.utils"
44
local Runner = require "nvim-tree.git.runner"
5-
local Watch = require "nvim-tree.explorer.watch"
65
local Watcher = require("nvim-tree.watcher").Watcher
76
local Iterator = require "nvim-tree.iterators.node-iterator"
87
local explorer_node = require "nvim-tree.explorer.node"
@@ -165,34 +164,22 @@ function M.load_project_status(cwd)
165164
}
166165

167166
local watcher = nil
168-
169167
if M.config.filesystem_watchers.enable then
170168
log.line("watcher", "git start")
171169

172-
local git_directory = git_utils.get_git_directory(project_root)
173-
174-
if git_directory == nil then
175-
log.line("watcher", "could not found the location of .git folder")
176-
else
177-
local callback = function(w)
178-
log.line("watcher", "git event scheduled '%s'", w.project_root)
179-
utils.debounce("git:watcher:" .. w.project_root, M.config.filesystem_watchers.debounce_delay, function()
180-
if w.destroyed then
181-
return
182-
end
183-
reload_tree_at(w.project_root)
184-
end)
185-
end
186-
187-
-- Add GIT_DIR to the list of directory to ignore
188-
-- local base_gitdir = utils.path_basename(git_directory)
189-
-- Watch.ignore_dir(base_gitdir)
190-
Watch.ignore_dir(git_directory)
191-
192-
watcher = Watcher:new(git_directory, WATCHED_FILES, callback, {
193-
project_root = project_root,
194-
})
170+
local callback = function(w)
171+
log.line("watcher", "git event scheduled '%s'", w.project_root)
172+
utils.debounce("git:watcher:" .. w.project_root, M.config.filesystem_watchers.debounce_delay, function()
173+
if w.destroyed then
174+
return
175+
end
176+
reload_tree_at(w.project_root)
177+
end)
195178
end
179+
180+
watcher = Watcher:new(utils.path_join { project_root, ".git" }, WATCHED_FILES, callback, {
181+
project_root = project_root,
182+
})
196183
end
197184

198185
M.projects[project_root] = {

lua/nvim-tree/git/utils.lua

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local M = {}
22
local log = require "nvim-tree.log"
3-
local utils = require "nvim-tree.utils"
3+
4+
local has_cygpath = vim.fn.executable "cygpath" == 1
45

56
function M.get_toplevel(cwd)
67
local profile = log.profile_start("git toplevel %s", cwd)
@@ -17,9 +18,16 @@ function M.get_toplevel(cwd)
1718
return nil
1819
end
1920

20-
toplevel = utils.norm_path(toplevel)
21-
if toplevel == nil then
22-
return nil
21+
-- git always returns path with forward slashes
22+
if vim.fn.has "win32" == 1 then
23+
-- msys2 git support
24+
if has_cygpath then
25+
toplevel = vim.fn.system("cygpath -w " .. vim.fn.shellescape(toplevel))
26+
if vim.v.shell_error ~= 0 then
27+
return nil
28+
end
29+
end
30+
toplevel = toplevel:gsub("/", "\\")
2331
end
2432

2533
-- remove newline
@@ -86,28 +94,4 @@ function M.file_status_to_dir_status(status, cwd)
8694
return r
8795
end
8896

89-
function M.get_git_directory(cwd)
90-
local profile = log.profile_start("git directory %s", cwd)
91-
92-
local cmd = { "git", "-C", cwd, "rev-parse", "--absolute-git-dir" }
93-
log.line("git", vim.inspect(cmd))
94-
95-
local git_dir = vim.fn.system(cmd)
96-
97-
log.raw("git", git_dir)
98-
log.profile_end(profile)
99-
100-
if vim.v.shell_error ~= 0 or not git_dir or #git_dir == 0 or git_dir:match "fatal" then
101-
return nil
102-
end
103-
104-
git_dir = utils.norm_path(git_dir)
105-
if git_dir == nil then
106-
return nil
107-
end
108-
109-
-- remove newline
110-
return git_dir:sub(0, -2)
111-
end
112-
11397
return M

lua/nvim-tree/utils.lua

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ local M = {
55
debouncers = {},
66
}
77

8-
local has_cygpath = vim.fn.executable "cygpath" == 1
9-
108
M.is_unix = vim.fn.has "unix" == 1
119
M.is_macos = vim.fn.has "mac" == 1 or vim.fn.has "macunix" == 1
1210
M.is_wsl = vim.fn.has "wsl" == 1
11+
-- false for WSL
1312
M.is_windows = vim.fn.has "win32" == 1 or vim.fn.has "win32unix" == 1
1413

1514
function M.str_find(haystack, needle)
@@ -39,26 +38,6 @@ function M.path_split(path)
3938
return path:gmatch("[^" .. path_separator .. "]+" .. path_separator .. "?")
4039
end
4140

42-
--- Normalise a path:
43-
--- windows: replace slashes with backslashes
44-
--- cygwin: resolve path first via cygpath
45-
--- @param path string
46-
--- @return string|nil nil on cygpath failure
47-
function M.norm_path(path)
48-
if M.is_windows then
49-
-- msys2 git support
50-
if has_cygpath then
51-
path = vim.fn.system("cygpath -w " .. vim.fn.shellescape(path))
52-
if vim.v.shell_error ~= 0 then
53-
return nil
54-
end
55-
end
56-
path = path:gsub("/", "\\")
57-
end
58-
59-
return path
60-
end
61-
6241
---Get the basename of the given path.
6342
---@param path string
6443
---@return string

0 commit comments

Comments
 (0)