Add keys to review a single commit and a branch's commits
<leader>gd/gm cover uncommitted work and a whole branch, but neither answers "what did that one commit on main do". <leader>gr opens the explorer on one commit's files, defaulting to a sha under the cursor so it works straight from a log or a commit message. <leader>gR lists the commits HEAD has that a base branch does not, oldest first. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
417542807b
commit
c674ee3e93
1 changed files with 38 additions and 0 deletions
|
|
@ -56,3 +56,41 @@ map('<leader>gm', function()
|
|||
end
|
||||
end)
|
||||
end, 'Diff against branch')
|
||||
|
||||
-- A commit-ish under the cursor, or nil. Lets <leader>gr be pressed straight on
|
||||
-- a sha pasted in a commit message, a code comment or a fugitive/log buffer.
|
||||
-- ^{commit} so a tag or tree does not pass as something diffable, and --quiet
|
||||
-- so a cword like 'function' fails silently instead of shouting.
|
||||
local function commit_under_cursor()
|
||||
local cword = vim.fn.expand('<cword>')
|
||||
if cword == '' then
|
||||
return nil
|
||||
end
|
||||
vim.fn.systemlist('git rev-parse --verify --quiet ' .. vim.fn.shellescape(cword) .. '^{commit}')
|
||||
if vim.v.shell_error ~= 0 then
|
||||
return nil
|
||||
end
|
||||
return cword
|
||||
end
|
||||
|
||||
map('<leader>gr', function()
|
||||
local default = commit_under_cursor() or 'HEAD'
|
||||
vim.ui.input({ prompt = 'Review commit: ', default = default }, function(rev)
|
||||
if rev and rev ~= '' then
|
||||
-- rev^ rev, not `history`, so the explorer opens on that one commit's
|
||||
-- files. A merge commit diffs against its first parent, as git does.
|
||||
vim.cmd('CodeDiff ' .. rev .. '^ ' .. rev)
|
||||
end
|
||||
end)
|
||||
end, 'Review a commit')
|
||||
|
||||
map('<leader>gR', function()
|
||||
vim.ui.input({ prompt = 'Commits since: ', default = default_branch() }, function(rev)
|
||||
if rev and rev ~= '' then
|
||||
-- Commit-by-commit rather than squashed: the history panel lists each
|
||||
-- commit the branch is missing, oldest first, so they read in the order
|
||||
-- they were made.
|
||||
vim.cmd('CodeDiff history ' .. rev .. '..HEAD --reverse')
|
||||
end
|
||||
end)
|
||||
end, 'Review commits since branch')
|
||||
|
|
|
|||
Loading…
Reference in a new issue