diff --git a/lua/git/cmd.lua b/lua/git/cmd.lua index 2aa6aff..6270c96 100644 --- a/lua/git/cmd.lua +++ b/lua/git/cmd.lua @@ -119,7 +119,13 @@ local function run_in_split(worktree, args, conf) vim.b[buf].git_parent_ref = repo.rev_parse(worktree, user_ref .. "^", true) end - pcall(vim.api.nvim_buf_set_name, buf, "git://" .. (sha or user_ref)) + -- Per-subcommand scheme so `:G show ` doesn't collide with + -- the cat-file URI form `git://` used by the gitlog flow. + pcall( + vim.api.nvim_buf_set_name, + buf, + "git" .. args[1] .. "://" .. (sha or user_ref) + ) vim.bo[buf].filetype = conf.ft else vim.bo[buf].filetype = conf.ft diff --git a/lua/git/object.lua b/lua/git/object.lua index 565b527..c1eea25 100644 --- a/lua/git/object.lua +++ b/lua/git/object.lua @@ -115,18 +115,21 @@ local function show_diff(ctx, section) return end local parent = ctx.parent_ref or "0" + -- blob_buf handles the absent (zero-blob) case by returning an empty + -- buffer, which keeps `:diffsplit` from triggering BufReadCmd against + -- a non-existent revspec and logging an error. local left = blob_buf(ctx.worktree, section.pre_blob, section.pre_path, parent) local right = blob_buf(ctx.worktree, section.post_blob, section.post_path, ctx.ref) vim.cmd.normal({ "m'", bang = true }) - local left_win = vim.api.nvim_get_current_win() - vim.api.nvim_set_current_buf(left) - vim.wo[left_win].diff = true - local right_win = - vim.api.nvim_open_win(right, true, { split = "right", win = left_win }) - vim.wo[right_win].diff = true - vim.api.nvim_set_current_win(left_win) + vim.api.nvim_set_current_buf(right) + -- `:diffsplit` is the same path `M.split` uses; Vim's built-in diff + -- machinery handles the diff option setup on both windows. + vim.cmd( + "leftabove vert diffsplit " + .. vim.fn.fnameescape(vim.api.nvim_buf_get_name(left)) + ) end ---@class ow.Git.OpenCommitOpts @@ -265,7 +268,8 @@ function M.open_under_cursor() -- Cat-file header navigation: `parent ` (commit), `tree ` -- (commit / tag), `object ` (tag's referent) all reference -- another git object. - local sha = line:match("^parent (%x+)$") + local sha = line:match("^commit (%x+)$") + or line:match("^parent (%x+)$") or line:match("^tree (%x+)$") or line:match("^object (%x+)$") if sha then