git.lua 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. local diffview = require('diffview')
  2. local MiniDiff = require('mini.diff')
  3. local util = require('user.util')
  4. diffview.setup({
  5. use_icons = false,
  6. signs = {
  7. fold_closed = ' ',
  8. fold_open = '-',
  9. }
  10. })
  11. -- shows added/removed/changed lines
  12. MiniDiff.setup({
  13. -- keymap #bracketed
  14. -- ]h / [h - navigate by hunks
  15. view = {
  16. style = 'sign',
  17. signs = {
  18. delete = '_',
  19. },
  20. },
  21. source = {
  22. MiniDiff.gen_source.git(),
  23. -- handle fugitive paths
  24. {
  25. name = 'fugitive',
  26. attach = function(buf_id)
  27. local resolved = util.resolve_git_path(buf_id)
  28. if not resolved or resolved.path == '' then
  29. return false
  30. end
  31. local source = vim.fn.FugitiveFind(string.format('%s~1:%s', resolved.commit, resolved.path))
  32. local text = vim.fn['fugitive#readfile'](source)
  33. MiniDiff.set_ref_text(buf_id, text)
  34. end
  35. }
  36. }
  37. })
  38. -- open status in current split without special flag (so navigating away closes it)
  39. -- https://github.com/tpope/vim-fugitive/issues/1296
  40. vim.keymap.set('n', '<Leader>gs', '<cmd>Gedit :<CR>')
  41. vim.keymap.set('n', '<Leader>gb', '<cmd>Telescope git_branches<CR>')
  42. vim.keymap.set('n', '<Leader>gd', MiniDiff.toggle_overlay)
  43. vim.keymap.set('n', '<Leader>gvi', '<cmd>DiffviewOpen<CR>')
  44. vim.keymap.set('n', '<Leader>gvr', '<cmd>DiffviewFileHistory --range=origin..HEAD<CR>')
  45. -- conflicts navigation #bracketed
  46. vim.keymap.set('n', '[x', '?^[<lt>=>]\\{7}<CR>')
  47. vim.keymap.set('n', ']x', '/^[<lt>=>]\\{7}<CR>')