Skip to content

Commit

Permalink
Update git_root on refresh, remove unused cwd
Browse files Browse the repository at this point in the history
  • Loading branch information
smatting committed Nov 16, 2023
1 parent 842c2f2 commit 6cbbe51
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
Empty file added init.lua
Empty file.
3 changes: 1 addition & 2 deletions lua/neogit/lib/git/repository.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local logger = require("neogit.logger")

-- git-status outputs files relative to the cwd.
--
-- Save the working directory to allow resolution to absolute paths since the
-- Save the git_root to allow resolution to absolute paths since the
-- cwd may change after the status is refreshed and used, especially if using
-- rooter plugins with lsp integration
-- stylua: ignore start
Expand All @@ -15,7 +15,6 @@ local function empty_state()
git_path = function(...)
return Path.new(root):joinpath(".git", ...)
end,
cwd = vim.fn.getcwd(),
git_root = root,
head = {
branch = nil,
Expand Down
20 changes: 14 additions & 6 deletions lua/neogit/lib/git/status.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ local tag_pattern = "(.-)%-([0-9]+)%-g%x+$"

local function update_status(state)
local git = require("neogit.lib.git")
-- git-status outputs files relative to the cwd.
--
-- Save the working directory to allow resolution to absolute paths since the
-- cwd may change after the status is refreshed and used, especially if using
-- rooter plugins with lsp integration
local cwd = vim.fn.getcwd()
local result = git.cli.status.porcelain(2).branch.call():trim()

Expand Down Expand Up @@ -160,12 +155,25 @@ local function update_status(state)
else
head.tag = { name = nil, distance = nil }
end
state.cwd = cwd

state.head = head
state.upstream = upstream
state.untracked.items = untracked_files
state.unstaged.items = unstaged_files
state.staged.items = staged_files

-- git-status outputs files relative to the cwd.
--
-- Save the git root to allow resolution to absolute paths since the
-- cwd may change after the status is refreshed and used, especially if using
-- rooter plugins with lsp integration
local git_root = require("neogit.lib.git.cli").git_root()
state.git_root = git_root
local Path = require("plenary.path")
state.git_path = function(...)
return Path.new(git_root):joinpath(".git", ...)
end

end

local function update_branch_information(state)
Expand Down

0 comments on commit 6cbbe51

Please sign in to comment.