From 3ffcc0c7b06ee3ce34ee4171bf2a2893b815ffa1 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 12 Oct 2026 18:27:41 +0200 Subject: [PATCH] Extract worktreeOfFile from markWorktreeFiles The files panel is going to need to find the worktree of an entry too. Co-Authored-By: Claude Opus 5.5 (1M context) --- pkg/gui/controllers/helpers/refresh_helper.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/gui/controllers/helpers/refresh_helper.go b/pkg/gui/controllers/helpers/refresh_helper.go index 0cbde1f70..4b3d1c429 100644 --- a/pkg/gui/controllers/helpers/refresh_helper.go +++ b/pkg/gui/controllers/helpers/refresh_helper.go @@ -1476,10 +1476,7 @@ func markWorktreeFiles(files []*models.File, worktrees []*models.Worktree, workt changed := false for _, file := range files { - absPath := filepath.Join(worktreePath, file.Path) - isWorktree := lo.SomeBy(worktrees, func(worktree *models.Worktree) bool { - return worktree.Path == absPath - }) + _, isWorktree := worktreeOfFile(file, worktrees, worktreePath) if isWorktree != file.IsWorktree { file.IsWorktree = isWorktree @@ -1490,6 +1487,15 @@ func markWorktreeFiles(files []*models.File, worktrees []*models.Worktree, workt return changed } +// worktreeOfFile returns the worktree that an entry of the files panel is, if +// it is one. worktreePath is the path of the worktree that we're in. +func worktreeOfFile(file *models.File, worktrees []*models.Worktree, worktreePath string) (*models.Worktree, bool) { + absPath := filepath.Join(worktreePath, file.Path) + return lo.Find(worktrees, func(worktree *models.Worktree) bool { + return worktree.Path == absPath + }) +} + // the reflogs panel is the only panel where we cache data, in that we only // load entries that have been created since we last ran the call. This means // we need to be more careful with how we use this, and to ensure we're emptying