lewis6991 / gitsigns.nvim

Git integration for buffers
MIT License
4.91k stars 187 forks source link

FR: Signs for hunks changed in last commit to file #1032

Closed chrisgrieser closed 3 months ago

chrisgrieser commented 3 months ago

Currently, gitsigns.nvim only shows uncommitted, unchanged hunks, i.e., the present state.

Some I'd find useful is to display the sections of a file that were changed during the last commit that changed that file, i.e., the hunks from the last change of the file, which to me feels like it fits well with the rest of this plugin's feature set.

lewis6991 commented 3 months ago

Use :Gitsigns change_base HEAD~1

Adding signs for the diff of HEAD to HEAD~1 is out of scope as we only diff against the buffer text.

chrisgrieser commented 3 months ago

Ah, didn't know that this was actually already possible. Thank you!

For reference for people finding this issue via search, my request can be solved with this, which effectively shows whatever changes were made in the last commit to the current file:

local file = vim.api.nvim_buf_get_name(0)
local gitArgs = { "git", "log", "-1", "--format=%h", "--", file }
local lastCommitToFile = vim.trim(vim.system(gitArgs):wait().stdout)
require("gitsigns").change_base(lastCommitToFile .. "^")