jesseduffield / jesseduffield/lazygit
Potential nil dereference in worktree porcelain parser
- Dominant language
- Go
- Stars
- 82.4k
- Forks
- 3k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 19
Description
Hi,
In `pkg/commands/git_commands/worktree_loader.go`, the porcelain output parser accesses `current.Head` and `current.Branch` without checking if `current` is nil.
`current` starts as nil and is also set to nil after encountering a "bare" line. If `git worktree list --porcelain` produces unexpected output (e.g., a "HEAD" or "branch" line without a preceding "worktree" line — which can happen with corrupted git state or manual worktree directory manipulation), this will panic.
This might be related to some of the worktree crashes reported in #5266.
A simple nil check before each access would make the parser more defensive.
Contributor guide
Assessment
This issue has not been assessed yet.