Add a test for opening a file of a branch checked out in another worktree

Pressing `o` on a file in the commit files panel has the same problem as
`e` had before the previous commit. If the commit is of a branch that
another worktree has checked out, the file is still opened from the
current worktree. The absolute path in the panel's copy menu points into
the current worktree too.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
Stefan Haller
2026-10-10 13:58:05 +02:00
co-authored by Claude Opus 5.5
parent 51e91fbb85
commit 6c4409b712
2 changed files with 71 additions and 0 deletions
+1
View File
@@ -703,6 +703,7 @@ var tests = []*components.IntegrationTest{
worktree.LocationCandidates,
worktree.NewWorktreePicker,
worktree.NewWorktreePickerRemote,
worktree.OpenFileOfBranchInOtherWorktree,
worktree.RemoveWorktreeAndBothBranches,
worktree.RemoveWorktreeAndBranch,
worktree.RemoveWorktreeAndDeleteLocalAndRemoteBranch,
@@ -0,0 +1,70 @@
package worktree
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var OpenFileOfBranchInOtherWorktree = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Open a file of a commit of a branch that is checked out in another worktree, and copy its absolute path",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {
config.GetUserConfig().OS.Open = "echo {{filename}} > open-command"
config.GetUserConfig().OS.CopyToClipboardCmd = "printf '%s' {{text}} > clipboard"
},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("README.md", "hello world")
shell.Commit("initial commit")
shell.NewBranch("mybranch")
shell.CreateFileAndAdd("file.txt", "content")
shell.Commit("add file")
shell.Checkout("master")
shell.AddWorktreeCheckout("mybranch", "../linked-worktree")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Branches().
Focus().
Lines(
Contains("master").IsSelected(),
Contains("mybranch (worktree linked-worktree)"),
).
NavigateToLine(Contains("mybranch")).
PressEnter()
t.Views().SubCommits().
IsFocused().
Lines(
Contains("add file").IsSelected(),
Contains("initial commit"),
).
PressEnter()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("A file.txt").IsSelected(),
).
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() {
t.ExpectPopup().Menu().
Title(Equals("Copy to clipboard")).
Select(Contains("Absolute path")).
Confirm()
t.ExpectToast(Equals("File path copied to clipboard"))
/* EXPECTED:
t.FileSystem().FileContent("clipboard", Contains("/linked-worktree/file.txt"))
ACTUAL: */
t.FileSystem().FileContent("clipboard", Contains("/repo/file.txt"))
})
},
})