NeogitOrg / neogit

An interactive and powerful Git interface for Neovim, inspired by Magit
MIT License
3.64k stars 218 forks source link

Using ":Neogit branch" to create a branch leads to error #1334

Closed sstark closed 1 month ago

sstark commented 1 month ago

Description

Trying to create a new branch using :Neogit branch (as opposed to :Neogit) leads to error message / stack trace.

Neovim version

NVIM v0.10.0 Build type: Release LuaJIT 2.1.1713773202 Run "nvim -V1 -v" for more info

Operating system and version

Manjaro Linux, 24.0.0

Steps to reproduce

In order to create a branch with Neogit, you have to :Neogit -> b -> n -> choose where to branch off -> enter branch name.

You can also reach that popup directly by using :Neogit branch and use the same commands. However, this way you get above error message when you press n.

Expected behavior

I would expect he same behaviour of the branch popup, no matter if it was opened directly with :Neogit branch or implicitly through :Neogit.

Or, if that is not supported, I would expect an appropriate message.

Actual behavior

Stacktrace is shown:

E5108: Error executing lua: ...ig/nvim/plugged/plenary.nvim/lua/plenary/async/async.lua:18: The coroutine failed with this message: ...ig/nvim/plugged/plenary.nvim/lua/plenary/async/async.lua:18: The coroutine failed with this message: ...nvim/plugged/neogit/lua/neogit/popups/branch/actions.lua:55: attempt to index field 'commits' (a nil value)
stack traceback:
        [C]: in function 'error'
        ...ig/nvim/plugged/plenary.nvim/lua/plenary/async/async.lua:18: in function 'callback_or_next'
        ...ig/nvim/plugged/plenary.nvim/lua/plenary/async/async.lua:45: in function 'callback'
        .../nvim/plugged/plenary.nvim/lua/plenary/async/control.lua:101: in function 'returned_function'
        ...ig/nvim/plugged/plenary.nvim/lua/plenary/async/async.lua:31: in function 'callback_or_next'
        ...ig/nvim/plugged/plenary.nvim/lua/plenary/async/async.lua:45: in function 'step'
        ...ig/nvim/plugged/plenary.nvim/lua/plenary/async/async.lua:48: in function 'execute'
        ...ig/nvim/plugged/plenary.nvim/lua/plenary/async/async.lua:118: in function 'cb'

After that, Neogit does not work properly anymore and I need to restart nvim to get it working again.

I assume the relevant error information is "attempt to index field 'commits' (a nil value)". The relevant line 55 in the code is:

{ popup.state.env.commits[1] },

and apperantly popup.state.env.commits is not initialised if the popup is run directly.

Minimal config

call plug#begin('~/.config/nvim/plugged')
Plug 'nvim-lua/plenary.nvim'
Plug 'TimUntersberger/neogit'
call plug#end()
lua <<EOF
local neogit = require('neogit')
neogit.setup {}
EOF