Skip to content

Pre checkout hook/event #1909

@KirkEasterson

Description

@KirkEasterson

Is your feature request related to a problem? Please describe.

I use an auto-session plugin that can create sessions based on the current git branch. I've created an autocommand to load a session when a branch is checked out.

    local neogit_group = vim.api.nvim_create_augroup("UserNeogitEvents", { clear = true })
    vim.api.nvim_create_autocmd({ "User" }, {
      desc = "Load session for checked out branch",
      pattern = "NeogitBranchCheckout",
      group = neogit_group,
      callback = function()
        local neogit = require("neogit")
        local autosession = require("auto-session")

        neogit.close()
        vim.cmd([[%bd!]])
        autosession.RestoreSession("", { show_message = false })
        neogit.open()
      end,
    })

This autocommand is useful for automatically loading sessions. But there exists the problem that the previous session is not saved before switching the branch. I can do this manually with :SessionSave, but I would prefer to have it automated like I have for loading sessions. From my understanding, there is currently no way for me to automate this with neogit.

Describe the solution you'd like

Ideally neogit would allow for some PreCheckoutHook when I can run some lua function. The pros are that it would fix my problem. The cons are that neogit would have a difference between supporting events and custom hooks. This also leads to the question "what other hooks should be supported?" and "should neogit offer both hooks and event?".

Describe alternatives you've considered
Saving the session manually as I described above.

Additional context
I am willing to help contribute to solve my problem and offer more features to other users. But I understand if this feature request would be denied.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions