From 6cbbe517bae37bd57d2664dc970923500e7479f2 Mon Sep 17 00:00:00 2001 From: Stefan Matting Date: Thu, 16 Nov 2023 01:13:56 +0100 Subject: [PATCH] Update git_root on refresh, remove unused cwd --- init.lua | 0 lua/neogit/lib/git/repository.lua | 3 +-- lua/neogit/lib/git/status.lua | 20 ++++++++++++++------ 3 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 init.lua diff --git a/init.lua b/init.lua new file mode 100644 index 000000000..e69de29bb diff --git a/lua/neogit/lib/git/repository.lua b/lua/neogit/lib/git/repository.lua index db67066c8..fe7931864 100644 --- a/lua/neogit/lib/git/repository.lua +++ b/lua/neogit/lib/git/repository.lua @@ -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 @@ -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, diff --git a/lua/neogit/lib/git/status.lua b/lua/neogit/lib/git/status.lua index 87904490c..fd566f24a 100644 --- a/lua/neogit/lib/git/status.lua +++ b/lua/neogit/lib/git/status.lua @@ -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() @@ -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)