From 6c4409b712347340a942e4f39c3ff1f2f41370f5 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 9 Oct 2026 19:58:57 +0200 Subject: [PATCH] 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) --- pkg/integration/tests/test_list.go | 1 + .../open_file_of_branch_in_other_worktree.go | 70 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 pkg/integration/tests/worktree/open_file_of_branch_in_other_worktree.go diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index d031d7d5b..207a2db70 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -703,6 +703,7 @@ var tests = []*components.IntegrationTest{ worktree.LocationCandidates, worktree.NewWorktreePicker, worktree.NewWorktreePickerRemote, + worktree.OpenFileOfBranchInOtherWorktree, worktree.RemoveWorktreeAndBothBranches, worktree.RemoveWorktreeAndBranch, worktree.RemoveWorktreeAndDeleteLocalAndRemoteBranch, 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 new file mode 100644 index 000000000..27ace3234 --- /dev/null +++ b/pkg/integration/tests/worktree/open_file_of_branch_in_other_worktree.go @@ -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")) + }) + }, +})