Skip to content

Commit 1a78246

Browse files
author
Damien MEHALA
committed
Code review
- move norm_path to utils.lua - fix comment #2012
1 parent 5860ac3 commit 1a78246

File tree

4 files changed

+24
-22
lines changed

4 files changed

+24
-22
lines changed

lua/nvim-tree/explorer/explore.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ local function populate_children(handle, cwd, node, git_status)
3030

3131
t = get_type_from(t, abs)
3232
if
33-
abs ~= git_status.git_dir
34-
and not filters.should_filter(abs, filter_status)
33+
not filters.should_filter(abs, filter_status)
3534
and not nodes_by_path[abs]
3635
and Watcher.is_fs_event_capable(abs)
3736
then

lua/nvim-tree/git/init.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ function M.load_project_status(cwd)
162162
end)
163163
end
164164

165+
-- Add $GIT_DIR to the list of directory to ignore
166+
local base_gitdir = utils.path_basename(git_directory)
167+
table.insert(M.config.filesystem_watchers.ignore_dirs, base_gitdir)
168+
165169
watcher = Watcher:new(git_directory, WATCHED_FILES, callback, {
166170
project_root = project_root,
167171
})
@@ -172,7 +176,6 @@ function M.load_project_status(cwd)
172176
files = git_status,
173177
dirs = git_utils.file_status_to_dir_status(git_status, project_root),
174178
watcher = watcher,
175-
git_dir = git_directory,
176179
}
177180
return M.projects[project_root]
178181
end

lua/nvim-tree/git/utils.lua

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
11
local M = {}
22
local log = require "nvim-tree.log"
3-
4-
local has_cygpath = vim.fn.executable "cygpath" == 1
5-
6-
local function norm_path(path)
7-
-- git always returns path with forward slashes
8-
if vim.fn.has "win32" == 1 then
9-
-- msys2 git support
10-
if has_cygpath then
11-
path = vim.fn.system("cygpath -w " .. vim.fn.shellescape(path))
12-
if vim.v.shell_error ~= 0 then
13-
return nil
14-
end
15-
end
16-
path = path:gsub("/", "\\")
17-
end
18-
19-
return path
20-
end
3+
local utils = require "nvim-tree.utils"
214

225
function M.get_toplevel(cwd)
236
local profile = log.profile_start("git toplevel %s", cwd)
@@ -34,7 +17,7 @@ function M.get_toplevel(cwd)
3417
return nil
3518
end
3619

37-
toplevel = norm_path(toplevel)
20+
toplevel = utils.norm_path(toplevel)
3821
if toplevel == nil then
3922
return nil
4023
end

lua/nvim-tree/utils.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ local M = {
55
debouncers = {},
66
}
77

8+
local has_cygpath = vim.fn.executable "cygpath" == 1
9+
810
M.is_unix = vim.fn.has "unix" == 1
911
M.is_macos = vim.fn.has "mac" == 1 or vim.fn.has "macunix" == 1
1012
M.is_wsl = vim.fn.has "wsl" == 1
@@ -42,6 +44,21 @@ function M.path_split(path)
4244
return path:gmatch("[^" .. path_separator .. "]+" .. path_separator .. "?")
4345
end
4446

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+
4562
---Get the basename of the given path.
4663
---@param path string
4764
---@return string

0 commit comments

Comments
 (0)