summaryrefslogtreecommitdiffstats
path: root/.config/nvim/lua/plugins/git.lua
blob: db1f4355be57b7d9e0664833f9a13b3728921717 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
return {
    {
        "purarue/gitsigns-yadm.nvim",
        lazy = true,
    },
    {
        "lewis6991/gitsigns.nvim",
        event = { "BufReadPost", "VeryLazy" },
        opts = {
            signs                        = {
                add          = { text = '│' },
                change       = { text = '~' },
                delete       = { text = '_' },
                topdelete    = { text = '‾' },
                changedelete = { text = '~' },
                untracked    = { text = '┆' },
            },
            _on_attach_pre               = function(_, callback)
                if vim.fn.executable("yadm") == 1 then
                    require("gitsigns-yadm").yadm_signs(callback)
                else
                    callback()
                end
            end,
            signcolumn                   = true,  -- Toggle with `:Gitsigns toggle_signs`
            numhl                        = false, -- Toggle with `:Gitsigns toggle_numhl`
            linehl                       = false, -- Toggle with `:Gitsigns toggle_linehl`
            word_diff                    = false, -- Toggle with `:Gitsigns toggle_word_diff`
            watch_gitdir                 = {
                follow_files = true
            },
            attach_to_untracked          = true,
            current_line_blame           = false, -- Toggle with `:Gitsigns toggle_current_line_blame`
            current_line_blame_opts      = {
                virt_text = true,
                virt_text_pos = 'eol', -- 'eol' | 'overlay' | 'right_align'
                delay = 1000,
                ignore_whitespace = false,
            },
            current_line_blame_formatter = '<author>, <author_time:%Y-%m-%d> - <summary>',
            sign_priority                = 6,
            update_debounce              = 100,
            status_formatter             = nil,   -- Use default
            max_file_length              = 40000, -- Disable if file is longer than this (in lines)
            preview_config               = {
                -- Options passed to nvim_open_win
                border = 'single',
                style = 'minimal',
                relative = 'cursor',
                row = 0,
                col = 1
            },
            on_attach                    = function(bufnr)
                local gs = package.loaded.gitsigns

                local function map(mode, l, r, desc, opts)
                    opts = opts or {}
                    opts.buffer = bufnr
                    opts.desc = desc
                    vim.keymap.set(mode, l, r, opts)
                end

                -- navigation
                map('n', ']c', function()
                    if vim.wo.diff then return ']c' end
                    vim.schedule(function() gs.next_hunk() end)
                    return '<Ignore>'
                end, "jump to next hunk", { expr = true })

                map('n', '[c', function()
                    if vim.wo.diff then return '[c' end
                    vim.schedule(function() gs.prev_hunk() end)
                    return '<Ignore>'
                end, "jump to previous hunk", { expr = true })

                -- Actions
                map('n', '<leader>hs', gs.stage_hunk, "stage hunk")
                map('n', '<leader>hr', gs.reset_hunk, "reset hunk")
                map('v', '<leader>hs', function() gs.stage_hunk { vim.fn.line('.'), vim.fn.line('v') } end,
                    "stage selection")
                map('v', '<leader>hr', function() gs.reset_hunk { vim.fn.line('.'), vim.fn.line('v') } end,
                    "reset selection")
                map('n', '<leader>hS', gs.stage_buffer, "stage buffer")
                map('n', '<leader>hu', gs.undo_stage_hunk, "undo stage hunk")
                map('n', '<leader>hR', gs.reset_buffer, "undo reset buffer")
                map('n', '<leader>hp', gs.preview_hunk, "preview hunk")
                map('n', '<leader>hb', function() gs.blame_line { full = true } end, "blame line")
                map('n', '<leader>tb', gs.toggle_current_line_blame, "toggle current line blame")
                map('n', '<leader>hd', gs.diffthis, "diff this")
                map('n', '<leader>hD', function() gs.diffthis('~') end, "diff whole buffer")
                map('n', '<leader>td', gs.toggle_deleted, "toggle deleted")

                -- Text object
                map({ 'o', 'x' }, 'ih', ':<C-U>Gitsigns select_hunk<CR>', "select hunk")
            end

        },
    },
    {
        "NeogitOrg/neogit",
        dependencies = {
            "nvim-lua/plenary.nvim", -- required
            "sindrets/diffview.nvim", -- optional - Diff integration
            "nvim-telescope/telescope.nvim", -- optional
        },
        cmd="Neogit",
        config = true
    }
}