Skip to content
Merged
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
49 changes: 37 additions & 12 deletions lua/codediff/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,12 @@ local function handle_dir_diff(dir1, dir2)
end

local function handle_explorer(revision, revision2)
-- Use current buffer's directory if available, otherwise use cwd
-- Try buffer path first (consistent with original behavior), fallback to cwd
local current_buf = vim.api.nvim_get_current_buf()
local current_file = vim.api.nvim_buf_get_name(current_buf)
local check_path = current_file ~= "" and current_file or vim.fn.getcwd()

-- Check if in git repository
git.get_git_root(check_path, function(err_root, git_root)
if err_root then
vim.schedule(function()
vim.notify(err_root, vim.log.levels.ERROR)
end)
return
end
local cwd = vim.fn.getcwd()

local function open_explorer(git_root)
local function process_status(err_status, status_result, original_rev, modified_rev)
vim.schedule(function()
if err_status then
Expand Down Expand Up @@ -244,7 +236,40 @@ local function handle_explorer(revision, revision2)
process_status(err_status, status_result, nil, nil)
end)
end
end)
end

-- Try buffer path first if available
if current_file ~= "" then
git.get_git_root(current_file, function(err_file, git_root_file)
if not err_file then
open_explorer(git_root_file)
return
end

-- Buffer path failed, try cwd as fallback
git.get_git_root(cwd, function(err_cwd, git_root_cwd)
if not err_cwd then
open_explorer(git_root_cwd)
return
end
-- Both failed
vim.schedule(function()
vim.notify("Not in a git repository", vim.log.levels.ERROR)
end)
end)
end)
else
-- No buffer, try cwd directly
git.get_git_root(cwd, function(err_cwd, git_root)
if err_cwd then
vim.schedule(function()
vim.notify(err_cwd, vim.log.levels.ERROR)
end)
return
end
open_explorer(git_root)
end)
end
end

function M.vscode_merge(opts)
Expand Down