|
@@ -12,6 +12,32 @@ vim.filetype.add({
|
|
|
},
|
|
|
})
|
|
|
|
|
|
+-- helpers
|
|
|
+local function resolve_git_path(buf_id)
|
|
|
+ local bufname = vim.api.nvim_buf_get_name(buf_id)
|
|
|
+ if not vim.startswith(bufname, "fugitive://") then
|
|
|
+ return false
|
|
|
+ end
|
|
|
+
|
|
|
+ local parsed = vim.fn.FugitiveParse(bufname)
|
|
|
+ local resolved_path = parsed[1]
|
|
|
+ local repo = parsed[2]
|
|
|
+
|
|
|
+ if resolved_path == "" then
|
|
|
+ return false
|
|
|
+ end
|
|
|
+
|
|
|
+ local parts = vim.split(resolved_path, ':')
|
|
|
+ local commit = parts[1]
|
|
|
+ local path = parts[2]
|
|
|
+
|
|
|
+ return {
|
|
|
+ repo = repo,
|
|
|
+ commit = commit,
|
|
|
+ path = path,
|
|
|
+ }
|
|
|
+end
|
|
|
+
|
|
|
-- file/buffer/etc picker
|
|
|
local telescope_actions = require('telescope.actions')
|
|
|
local action_state = require('telescope.actions.state')
|
|
@@ -133,25 +159,18 @@ end
|
|
|
|
|
|
-- custom picker for files within a commit
|
|
|
_G.commit_files = function(opts)
|
|
|
- local current_path = vim.api.nvim_buf_get_name(0)
|
|
|
- local parsed = vim.fn.FugitiveParse(current_path)
|
|
|
- local resolved_path = parsed[1]
|
|
|
- local repo = parsed[2]
|
|
|
-
|
|
|
- if resolved_path == "" then
|
|
|
+ local resolved = resolve_git_path(0)
|
|
|
+ if not resolved then
|
|
|
vim.print("current file is not a fugitive path")
|
|
|
return
|
|
|
end
|
|
|
|
|
|
- local parts = vim.split(resolved_path, ':')
|
|
|
- local commit = parts[1]
|
|
|
-
|
|
|
opts = opts or {}
|
|
|
telescope_pickers.new(opts, {
|
|
|
- prompt_title = commit,
|
|
|
- finder = telescope_finders.new_oneshot_job({ "git", "ls-tree", "--name-only", "-r", commit }, {
|
|
|
+ prompt_title = resolved.commit,
|
|
|
+ finder = telescope_finders.new_oneshot_job({ "git", "ls-tree", "--name-only", "-r", resolved.commit }, {
|
|
|
entry_maker = function(entry)
|
|
|
- local path = string.format("fugitive://%s//%s/%s", repo, commit, entry)
|
|
|
+ local path = string.format("fugitive://%s//%s/%s", resolved.repo, resolved.commit, entry)
|
|
|
return {
|
|
|
path = path,
|
|
|
value = entry,
|
|
@@ -186,7 +205,32 @@ _G.commit_files = function(opts)
|
|
|
end
|
|
|
|
|
|
-- shows added/removed/changed lines
|
|
|
-require('gitsigns').setup()
|
|
|
+local MiniDiff = require('mini.diff')
|
|
|
+MiniDiff.setup({
|
|
|
+ view = {
|
|
|
+ style = 'sign',
|
|
|
+ signs = {
|
|
|
+ delete = '_',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ source = {
|
|
|
+ MiniDiff.gen_source.git(),
|
|
|
+ -- handle fugitive paths
|
|
|
+ {
|
|
|
+ name = "fugitive",
|
|
|
+ attach = function(buf_id)
|
|
|
+ local resolved = resolve_git_path(buf_id)
|
|
|
+ if not resolved or resolved.path == "" then
|
|
|
+ return false
|
|
|
+ end
|
|
|
+
|
|
|
+ local source = vim.fn.FugitiveFind(string.format("%s~1:%s", resolved.commit, resolved.path))
|
|
|
+ local text = vim.fn['fugitive#readfile'](source)
|
|
|
+ MiniDiff.set_ref_text(buf_id, text)
|
|
|
+ end
|
|
|
+ }
|
|
|
+ }
|
|
|
+})
|
|
|
|
|
|
require('mini.statusline').setup({
|
|
|
content = {
|