From a38cecee16a4a3d46dd8cf0ccb31244dd5f58113 Mon Sep 17 00:00:00 2001 From: easonysliu Date: Sat, 14 Mar 2026 00:13:51 +0800 Subject: [PATCH] fix: guard against nil current worktree in porcelain parser Co-Authored-By: Claude (claude-opus-4-6) --- pkg/commands/git_commands/worktree_loader.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/commands/git_commands/worktree_loader.go b/pkg/commands/git_commands/worktree_loader.go index 0e3615f13..a3abf6102 100644 --- a/pkg/commands/git_commands/worktree_loader.go +++ b/pkg/commands/git_commands/worktree_loader.go @@ -68,10 +68,14 @@ func (self *WorktreeLoader) GetWorktrees() ([]*models.Worktree, error) { GitDir: "", } } else if strings.HasPrefix(splitLine, "HEAD ") { - current.Head = strings.SplitN(splitLine, " ", 2)[1] + if current != nil { + current.Head = strings.SplitN(splitLine, " ", 2)[1] + } } else if strings.HasPrefix(splitLine, "branch ") { - branch := strings.SplitN(splitLine, " ", 2)[1] - current.Branch = strings.TrimPrefix(branch, "refs/heads/") + if current != nil { + branch := strings.SplitN(splitLine, " ", 2)[1] + current.Branch = strings.TrimPrefix(branch, "refs/heads/") + } } }