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

If you enter a branch in the branches panel, and that branch is checked
out in another worktree, pressing `e` on a line of a commit's diff opens
the file in the current worktree. The same happens for `e` on a file in
the commit files panel entered from there. The current worktree may not
have the file at all, as in this test, or have it in a different state
than the branch has it. The line number is carried forward to the
current worktree's version of the file too, and this gives line 0 here.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Stefan Haller
2026-10-10 13:58:04 +02:00
co-authored by Claude Opus 5.5
parent f343c8fd50
commit f9a3dc7be7
2 changed files with 78 additions and 0 deletions
+1
View File
@@ -694,6 +694,7 @@ var tests = []*components.IntegrationTest{
worktree.DetachWorktreeFromBranch,
worktree.DotfileBareRepo,
worktree.DoubleNestedLinkedSubmodule,
worktree.EditFileOfBranchInOtherWorktree,
worktree.ExcludeFileInWorktree,
worktree.FastForwardWorktreeBranch,
worktree.FastForwardWorktreeBranchShouldNotPolluteCurrentWorktree,
@@ -0,0 +1,77 @@
package worktree
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var EditFileOfBranchInOtherWorktree = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Edit a file of a commit of a branch that is checked out in another worktree",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {
config.GetUserConfig().Gui.UseHunkModeInDiffView = false
config.GetUserConfig().OS.Edit = "echo {{filename}} > edit-command"
config.GetUserConfig().OS.EditAtLine = "echo {{filename}}:{{line}} > edit-command"
},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("README.md", "hello world")
shell.Commit("initial commit")
shell.NewBranch("mybranch")
shell.CreateFileAndAdd("file.txt", "1\n2\n3\n")
shell.Commit("add file")
shell.Checkout("master")
shell.AddWorktreeCheckout("mybranch", "../linked-worktree")
// Move the lines of the file down in the linked worktree, so that a line of
// the commit's diff is at a different line of the file there
shell.UpdateFile("../linked-worktree/file.txt", "0\n1\n2\n3\n")
},
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"),
).
Press(keys.Universal.FocusMainView)
t.Views().Main().
IsFocused().
NavigateToLine(Contains("+2")).
Press(keys.Universal.Edit).
Tap(func() {
/* EXPECTED:
t.FileSystem().FileContent("edit-command", Contains("/linked-worktree/file.txt:3\n"))
ACTUAL: */
t.FileSystem().FileContent("edit-command", Contains("/repo/file.txt:0\n"))
}).
PressEscape()
t.Views().SubCommits().
IsFocused().
PressEnter()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("A file.txt").IsSelected(),
).
Press(keys.Universal.Edit).
Tap(func() {
/* EXPECTED:
t.FileSystem().FileContent("edit-command", Contains("/linked-worktree/file.txt\n"))
ACTUAL: */
t.FileSystem().FileContent("edit-command", Contains("/repo/file.txt\n"))
})
},
})