Skip to content
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

Update git_root on refresh #944

Closed
wants to merge 3 commits into from
Closed
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
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
19 changes: 13 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,24 @@ 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
5 changes: 3 additions & 2 deletions tests/util/git_harness.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ end

function M.in_prepared_repo(cb)
return function()
local dir = M.prepare_repository()
require("neogit").setup()
vim.cmd("Neogit")
a.util.block_on(status.reset)
local dir = M.prepare_repository()
vim.cmd("Neogit")
a.util.block_on(status.refresh)
a.util.block_on(function()
local _, err = pcall(cb, dir)
if err ~= nil then
Expand Down
Loading