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) <noreply@anthropic.com>
This commit is contained in:
Stefan HallerandClaude Opus 5.5 committed 2026-10-15 20:51:34 +02:00
1 parent 875641557b
commit 3ffcc0c7b0
1 file changed
+10 -4
+10 -4
View File
@@ -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