Skip to content

Commit bd0c2d3

Browse files
committed
fix: #1596
Don't lose the cwd when using `kind=replace` if it's nested within the repo
1 parent 4003847 commit bd0c2d3

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lua/neogit/lib/buffer.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ function Buffer:close(force)
214214
end
215215

216216
if self.kind == "replace" then
217+
if self.old_cwd then
218+
api.nvim_set_current_dir(self.old_cwd)
219+
self.old_cwd = nil
220+
end
221+
217222
api.nvim_buf_delete(self.handle, { force = force })
218223
return
219224
end
@@ -249,6 +254,11 @@ function Buffer:hide()
249254
vim.cmd("silent! 1only")
250255
vim.cmd("try | tabn # | catch /.*/ | tabp | endtry")
251256
elseif self.kind == "replace" then
257+
if self.old_cwd then
258+
api.nvim_set_current_dir(self.old_cwd)
259+
self.old_cwd = nil
260+
end
261+
252262
if self.old_buf and api.nvim_buf_is_loaded(self.old_buf) then
253263
api.nvim_set_current_buf(self.old_buf)
254264
self.old_buf = nil
@@ -288,6 +298,7 @@ function Buffer:show()
288298
local win
289299
if self.kind == "replace" then
290300
self.old_buf = api.nvim_get_current_buf()
301+
self.old_cwd = vim.uv.cwd()
291302
api.nvim_set_current_buf(self.handle)
292303
win = api.nvim_get_current_win()
293304
elseif self.kind == "tab" then

0 commit comments

Comments
 (0)