feat(git): navigate any git object from cat-file headers
This commit is contained in:
+7
-1
@@ -119,7 +119,13 @@ local function run_in_split(worktree, args, conf)
|
|||||||
vim.b[buf].git_parent_ref =
|
vim.b[buf].git_parent_ref =
|
||||||
repo.rev_parse(worktree, user_ref .. "^", true)
|
repo.rev_parse(worktree, user_ref .. "^", true)
|
||||||
end
|
end
|
||||||
pcall(vim.api.nvim_buf_set_name, buf, "git://" .. (sha or user_ref))
|
-- Per-subcommand scheme so `:G show <sha>` doesn't collide with
|
||||||
|
-- the cat-file URI form `git://<sha>` 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
|
vim.bo[buf].filetype = conf.ft
|
||||||
else
|
else
|
||||||
vim.bo[buf].filetype = conf.ft
|
vim.bo[buf].filetype = conf.ft
|
||||||
|
|||||||
+12
-8
@@ -115,18 +115,21 @@ local function show_diff(ctx, section)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
local parent = ctx.parent_ref or "0"
|
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 =
|
local left =
|
||||||
blob_buf(ctx.worktree, section.pre_blob, section.pre_path, parent)
|
blob_buf(ctx.worktree, section.pre_blob, section.pre_path, parent)
|
||||||
local right =
|
local right =
|
||||||
blob_buf(ctx.worktree, section.post_blob, section.post_path, ctx.ref)
|
blob_buf(ctx.worktree, section.post_blob, section.post_path, ctx.ref)
|
||||||
vim.cmd.normal({ "m'", bang = true })
|
vim.cmd.normal({ "m'", bang = true })
|
||||||
local left_win = vim.api.nvim_get_current_win()
|
vim.api.nvim_set_current_buf(right)
|
||||||
vim.api.nvim_set_current_buf(left)
|
-- `:diffsplit` is the same path `M.split` uses; Vim's built-in diff
|
||||||
vim.wo[left_win].diff = true
|
-- machinery handles the diff option setup on both windows.
|
||||||
local right_win =
|
vim.cmd(
|
||||||
vim.api.nvim_open_win(right, true, { split = "right", win = left_win })
|
"leftabove vert diffsplit "
|
||||||
vim.wo[right_win].diff = true
|
.. vim.fn.fnameescape(vim.api.nvim_buf_get_name(left))
|
||||||
vim.api.nvim_set_current_win(left_win)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@class ow.Git.OpenCommitOpts
|
---@class ow.Git.OpenCommitOpts
|
||||||
@@ -265,7 +268,8 @@ function M.open_under_cursor()
|
|||||||
-- Cat-file header navigation: `parent <sha>` (commit), `tree <sha>`
|
-- Cat-file header navigation: `parent <sha>` (commit), `tree <sha>`
|
||||||
-- (commit / tag), `object <sha>` (tag's referent) all reference
|
-- (commit / tag), `object <sha>` (tag's referent) all reference
|
||||||
-- another git object.
|
-- 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("^tree (%x+)$")
|
||||||
or line:match("^object (%x+)$")
|
or line:match("^object (%x+)$")
|
||||||
if sha then
|
if sha then
|
||||||
|
|||||||
Reference in New Issue
Block a user