Pre checkout hook/event
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 5.6k
- Forks
- 357
- Avg merge
- 15h 47m
- Merged PRs (30d)
- 2
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the NeogitBranchCheckout User event and the checkout flow that emits it. Decide how a pre-checkout callback should relate to existing events and other possible hooks; done means a Lua function can save the current auto-session before switching branches without disrupting checkout.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, lua, neovim
- Domain
- developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100