From 690509a8ccfed81718df3902a3040b5a9546606c Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 9 Oct 2026 19:59:19 +0200 Subject: [PATCH] Open files with `o` from the worktree that has the branch checked out Do the same for `o` in the commit files panel as the previous commits do for `e`. If the panel was entered from a branch that another worktree has checked out, open the file from that worktree. Co-Authored-By: Claude Opus 5.5 (1M context) --- pkg/gui/controllers/commits_files_controller.go | 2 +- pkg/gui/controllers/helpers/diff_helper.go | 7 +++++++ .../worktree/open_file_of_branch_in_other_worktree.go | 3 --- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/gui/controllers/commits_files_controller.go b/pkg/gui/controllers/commits_files_controller.go index 0c033d83e..b8995e7bd 100644 --- a/pkg/gui/controllers/commits_files_controller.go +++ b/pkg/gui/controllers/commits_files_controller.go @@ -428,7 +428,7 @@ func (self *CommitFilesController) canDiscardFileChanges(nodes []*filetree.Commi } func (self *CommitFilesController) open(node *filetree.CommitFileNode) error { - return self.c.Helpers().Files.OpenFile(node.GetPath()) + return self.c.Helpers().Diff.OpenFileOfDiff(node.GetPath()) } func (self *CommitFilesController) edit(nodes []*filetree.CommitFileNode) error { diff --git a/pkg/gui/controllers/helpers/diff_helper.go b/pkg/gui/controllers/helpers/diff_helper.go index 2b892e9fe..f620aed66 100644 --- a/pkg/gui/controllers/helpers/diff_helper.go +++ b/pkg/gui/controllers/helpers/diff_helper.go @@ -245,6 +245,13 @@ func (self *DiffHelper) EditFileOfDiffAtLine(path string, lineNumber int, viewNa return self.filesHelper.EditFileAtLine(path, lineNumber) } +// OpenFileOfDiff opens a file of the diff that the current side panel shows with the +// default application for it. Like EditFilesOfDiff, it opens the file from the +// worktree of the diff. +func (self *DiffHelper) OpenFileOfDiff(path string) error { + return self.filesHelper.OpenFile(self.pathInWorktreeOfDiff(path)) +} + // otherWorktreeOfDiff returns the path of the worktree to open files of the diff in // the current side panel from, if that isn't the current worktree. If the diff is of a // commit of a branch, and another worktree has that branch checked out, that is the diff --git a/pkg/integration/tests/worktree/open_file_of_branch_in_other_worktree.go b/pkg/integration/tests/worktree/open_file_of_branch_in_other_worktree.go index 27ace3234..78229d6e4 100644 --- a/pkg/integration/tests/worktree/open_file_of_branch_in_other_worktree.go +++ b/pkg/integration/tests/worktree/open_file_of_branch_in_other_worktree.go @@ -47,10 +47,7 @@ var OpenFileOfBranchInOtherWorktree = NewIntegrationTest(NewIntegrationTestArgs{ ). Press(keys.Universal.OpenFile). Tap(func() { - /* EXPECTED: t.FileSystem().FileContent("open-command", Contains("/linked-worktree/file.txt\n")) - ACTUAL: */ - t.FileSystem().FileContent("open-command", Contains("/repo/file.txt\n")) }). Press(keys.Files.CopyFileInfoToClipboard). Tap(func() {