Skip to content

Commit 6306140

Browse files
authored
feat(#1837): add git.disable_for_dirs (#2239)
* feat(##1837): add git.disabled_dirs * feat(#1837): add git.disable_for_dirs * feat(#1837): note disable_for_dirs evaluation
1 parent 73ab665 commit 6306140

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

doc/nvim-tree-lua.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ applying configuration.
458458
ignore = true,
459459
show_on_dirs = true,
460460
show_on_open_dirs = true,
461+
disable_for_dirs = {},
461462
timeout = 400,
462463
},
463464
modified = {
@@ -525,8 +526,7 @@ applying configuration.
525526
trash = true,
526527
},
527528
},
528-
experimental = {
529-
},
529+
experimental = {},
530530
log = {
531531
enable = false,
532532
truncate = false,
@@ -734,6 +734,11 @@ Git integration with icons and colors.
734734
Only relevant when `git.show_on_dirs` is `true`.
735735
Type: `boolean`, Default: `true`
736736

737+
*nvim-tree.git.disable_for_dirs*
738+
Disable git integration when git top-level matches these paths.
739+
May be relative, evaluated via |fnamemodify| `":p"`
740+
Type: `table`, Default: `{}`
741+
737742
*nvim-tree.git.timeout*
738743
Kills the git process after some time if it takes too long.
739744
Git integration will be disabled after 10 git jobs exceed this timeout.

lua/nvim-tree.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
492492
ignore = true,
493493
show_on_dirs = true,
494494
show_on_open_dirs = true,
495+
disable_for_dirs = {},
495496
timeout = 400,
496497
},
497498
modified = {

lua/nvim-tree/git/init.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,16 @@ function M.get_project_root(cwd)
107107
return nil
108108
end
109109

110-
M.cwd_to_project_root[cwd] = git_utils.get_toplevel(cwd)
110+
local toplevel = git_utils.get_toplevel(cwd)
111+
for _, disabled_for_dir in ipairs(M.config.git.disable_for_dirs) do
112+
local toplevel_norm = vim.fn.fnamemodify(toplevel, ":p")
113+
local disabled_norm = vim.fn.fnamemodify(disabled_for_dir, ":p")
114+
if toplevel_norm == disabled_norm then
115+
return nil
116+
end
117+
end
118+
119+
M.cwd_to_project_root[cwd] = toplevel
111120
return M.cwd_to_project_root[cwd]
112121
end
113122

lua/nvim-tree/git/utils.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ local log = require "nvim-tree.log"
33

44
local has_cygpath = vim.fn.executable "cygpath" == 1
55

6+
--- Retrieve the git toplevel directory
7+
--- @param cwd string path
8+
--- @return string|nil toplevel absolute path
69
function M.get_toplevel(cwd)
710
local profile = log.profile_start("git toplevel %s", cwd)
811

0 commit comments

Comments
 (0)