Skip to content

Commit

Permalink
Properly resolve directory based on source buffer name
Browse files Browse the repository at this point in the history
getcwd is not reliable and straight up doesnt work even when supplying correct
window number as first parameter so use filename instead

Closes #387

Signed-off-by: Tomas Slusny <[email protected]>
  • Loading branch information
deathbeam committed Aug 31, 2024
1 parent ce68b1f commit b8d713a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lua/CopilotChat/select.lua
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,13 @@ function M.gitdiff(source, staged)
return nil
end

local dir = vim.fn.getcwd()
local bufname = vim.api.nvim_buf_get_name(source.bufnr)
local file_path = bufname:gsub('^%w+://', '')
local dir = vim.fn.fnamemodify(file_path, ':h')
if not dir or dir == '' then
return nil
end

local cmd = 'git -C ' .. dir .. ' diff --no-color --no-ext-diff' .. (staged and ' --staged' or '')
local handle = io.popen(cmd)
if not handle then
Expand All @@ -170,7 +176,6 @@ function M.gitdiff(source, staged)

local result = handle:read('*a')
handle:close()

if not result or result == '' then
return nil
end
Expand Down

0 comments on commit b8d713a

Please sign in to comment.