Skip to content

feat(#1837): add git.disable_for_dirs #2239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ applying configuration.
ignore = true,
show_on_dirs = true,
show_on_open_dirs = true,
disable_for_dirs = {},
timeout = 400,
},
modified = {
Expand Down Expand Up @@ -525,8 +526,7 @@ applying configuration.
trash = true,
},
},
experimental = {
},
experimental = {},
log = {
enable = false,
truncate = false,
Expand Down Expand Up @@ -734,6 +734,11 @@ Git integration with icons and colors.
Only relevant when `git.show_on_dirs` is `true`.
Type: `boolean`, Default: `true`

*nvim-tree.git.disable_for_dirs*
Disable git integration when git top-level matches these paths.
May be relative, evaluated via |fnamemodify| `":p"`
Type: `table`, Default: `{}`

*nvim-tree.git.timeout*
Kills the git process after some time if it takes too long.
Git integration will be disabled after 10 git jobs exceed this timeout.
Expand Down
1 change: 1 addition & 0 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
ignore = true,
show_on_dirs = true,
show_on_open_dirs = true,
disable_for_dirs = {},
timeout = 400,
},
modified = {
Expand Down
11 changes: 10 additions & 1 deletion lua/nvim-tree/git/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,16 @@ function M.get_project_root(cwd)
return nil
end

M.cwd_to_project_root[cwd] = git_utils.get_toplevel(cwd)
local toplevel = git_utils.get_toplevel(cwd)
for _, disabled_for_dir in ipairs(M.config.git.disable_for_dirs) do
local toplevel_norm = vim.fn.fnamemodify(toplevel, ":p")
local disabled_norm = vim.fn.fnamemodify(disabled_for_dir, ":p")
if toplevel_norm == disabled_norm then
return nil
end
end

M.cwd_to_project_root[cwd] = toplevel
return M.cwd_to_project_root[cwd]
end

Expand Down
3 changes: 3 additions & 0 deletions lua/nvim-tree/git/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ local log = require "nvim-tree.log"

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

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

Expand Down