Skip to content
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
2 changes: 1 addition & 1 deletion lua/neo-tree/git/check-ignore.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ M.check = function(worktree_root, paths)
return nil
end
local ignored = {}
for ignored_path in utils.gsplit_plain(result, "\001") do
for ignored_path in utils.gsplit_plain(result, "\n") do
ignored[#ignored + 1] = utils.path_join(worktree_root, ignored_path)
end
return ignored, vim.v.shell_error == 0
Expand Down
43 changes: 38 additions & 5 deletions lua/neo-tree/git/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ local M = {}
---@field watcher neotree.sources.filesystem.Watcher?
---@field superproject_worktree_root string?
---@field status neotree.git.Status?
---@field status_progress neotree.git.WorktreeInfo.StatusProgress

---@class neotree.git.WorktreeInfo.StatusProgress
---@field tracked boolean?
---@field ignored boolean?
---@field untracked boolean?

---@type table<string, neotree.git.WorktreeInfo?>
M.worktrees = {}
Expand All @@ -54,6 +60,7 @@ local try_register_worktree = function(worktree_root, git_dir, superproject_work
git_dir = log.assert(git_dir, "Git dir should exist before registering"),
superproject_worktree_root = superproject_worktree_root,
status_diff = {},
status_progress = {},
}
M.worktrees[worktree_root] = worktree
end
Expand Down Expand Up @@ -147,11 +154,23 @@ end
---@param git_status neotree.git.Status
---@param base string?
---@param git_status_diff_base neotree.git.Status?
local change_worktree_git_status = function(worktree_root, git_status, base, git_status_diff_base)
---@param status_progress neotree.git.WorktreeInfo.StatusProgress?
local change_worktree_git_status = function(
worktree_root,
git_status,
base,
git_status_diff_base,
status_progress
)
assert(git_status)
local worktree =
assert(M.worktrees[worktree_root], "Could not find worktree for " .. worktree_root)
worktree.status = git_status
if status_progress then
for k, v in pairs(status_progress) do
worktree.status_progress[k] = worktree.status_progress[k] or v
end
end
if base then
worktree.status_diff[base] = git_status_diff_base
end
Expand Down Expand Up @@ -280,7 +299,12 @@ M.status = function(path, base_lookup, skip_bubbling, status_opts)
worktree_root,
git_status,
base_lookup and base_lookup[worktree_root],
git_status_over_base
git_status_over_base,
{
tracked = true,
ignored = true,
untracked = true,
}
)
return git_status, worktree_root, git_status_over_base
end
Expand Down Expand Up @@ -403,7 +427,9 @@ M.status_async = function(path, base_lookup, opts, callback)
end

--- Either the diff, or diff + ignored + all
change_worktree_git_status(worktree_root, fast_status)
change_worktree_git_status(worktree_root, fast_status, nil, nil, {
tracked = true,
})

if base then
git_diff.name_status_job(worktree_root, base, false, ctx, function(status)
Expand All @@ -417,6 +443,7 @@ M.status_async = function(path, base_lookup, opts, callback)
if status_existed then
return
end

-- Get ignored statuses
git_ls_files.ignored_job(ctx, function(ignored_paths, err)
if not ignored_paths then
Expand All @@ -425,7 +452,9 @@ M.status_async = function(path, base_lookup, opts, callback)
for _, ignored_path in ipairs(ignored_paths) do
ctx.git_status[ignored_path] = "!"
end
change_worktree_git_status(worktree_root, ctx.git_status)
change_worktree_git_status(worktree_root, ctx.git_status, nil, nil, {
ignored = true,
})
end)

-- Check for showUntrackedFiles and rescan for the full status
Expand Down Expand Up @@ -471,7 +500,11 @@ M.status_async = function(path, base_lookup, opts, callback)
log.error(err)
return
end
change_worktree_git_status(worktree_root, full_status)
change_worktree_git_status(worktree_root, full_status, nil, nil, {
tracked = true,
ignored = true,
untracked = true,
})
callback(worktree_root)
end)
end
Expand Down
8 changes: 6 additions & 2 deletions lua/neo-tree/sources/filesystem/lib/fs_scan.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ local mark_gitignored = function(cwd, items)
---@type [string, neotree.git.Status?][]
local roots_and_statuses = {}

-- Filter out all non-visible worktrees
-- Filter for visible worktrees
for worktree_root, worktree in pairs(git.worktrees) do
local is_upward = utils.is_subpath(worktree_root, cwd, true)
if is_upward or utils.is_subpath(cwd, worktree_root, true) then
roots_and_statuses[#roots_and_statuses + 1] = { worktree_root, worktree.status }
roots_and_statuses[#roots_and_statuses + 1] =
{ worktree_root, worktree.status_progress.ignored and worktree.status or nil }
end
if is_upward then
upward_status_found = true
Expand Down Expand Up @@ -74,8 +75,11 @@ local mark_gitignored = function(cwd, items)
local worktree_data = {}
for _, root_and_status in ipairs(roots_and_statuses) do
local worktree_root, status = unpack(root_and_status)
-- Second is list of items within the worktree root
worktree_data[worktree_root] = { status, {} }
end

-- Populate the items within the worktree root
for _, item in ipairs(items) do
for _, root_and_status in ipairs(roots_and_statuses) do
local worktree_root = root_and_status[1]
Expand Down
Loading