Skip to content

Commit

Permalink
fix: #1596
Browse files Browse the repository at this point in the history
Don't lose the cwd when using `kind=replace` if it's nested within the
repo
  • Loading branch information
CKolkey committed Dec 12, 2024
1 parent 4003847 commit bd0c2d3
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lua/neogit/lib/buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ function Buffer:close(force)
end

if self.kind == "replace" then
if self.old_cwd then
api.nvim_set_current_dir(self.old_cwd)
self.old_cwd = nil
end

api.nvim_buf_delete(self.handle, { force = force })
return
end
Expand Down Expand Up @@ -249,6 +254,11 @@ function Buffer:hide()
vim.cmd("silent! 1only")
vim.cmd("try | tabn # | catch /.*/ | tabp | endtry")
elseif self.kind == "replace" then
if self.old_cwd then
api.nvim_set_current_dir(self.old_cwd)
self.old_cwd = nil
end

if self.old_buf and api.nvim_buf_is_loaded(self.old_buf) then
api.nvim_set_current_buf(self.old_buf)
self.old_buf = nil
Expand Down Expand Up @@ -288,6 +298,7 @@ function Buffer:show()
local win
if self.kind == "replace" then
self.old_buf = api.nvim_get_current_buf()
self.old_cwd = vim.uv.cwd()
api.nvim_set_current_buf(self.handle)
win = api.nvim_get_current_win()
elseif self.kind == "tab" then
Expand Down

0 comments on commit bd0c2d3

Please sign in to comment.