jesseduffield.lazygit/pkg/integration/tests/worktree/add_from_remote_branch.go
Stefan Haller 737fb98967 Move the new-worktree keybinding from worktrees to universal
The command was renamed from "View worktree options" to "New worktree",
but its keybinding config key was still 'worktrees.viewWorktreeOptions'.
That name no longer matches the command, and the 'worktrees' section made
little sense: it held a single binding that isn't even used in the
worktrees panel (that panel uses universal.new), only in the branches,
remotes, tags, commits, and stash panels. Other keybinding sections are
named after the panel they're local to; this one wasn't local to any.

Move it to universal.newWorktree, which describes the action and drops the
spurious section, and migrate existing configs automatically.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-03 18:53:05 +02:00

62 lines
1.8 KiB
Go

package worktree
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var AddFromRemoteBranch = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Create a new local tracking branch and worktree from a remote branch",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("README.md", "hello world")
shell.Commit("initial commit")
shell.NewBranch("feature")
shell.CloneIntoRemote("origin")
shell.Checkout("master")
// drop the local branch so only the remote one remains
shell.RunCommand([]string{"git", "branch", "-D", "feature"})
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Remotes().
Focus().
Lines(
Contains("origin").IsSelected(),
).
PressEnter()
t.Views().RemoteBranches().
IsFocused().
NavigateToLine(Contains("feature")).
Press(keys.Universal.NewWorktree).
Tap(func() {
t.ExpectPopup().Menu().
Title(Equals("New worktree")).
Select(Contains("New local branch and worktree from 'origin/feature'")).
Confirm()
// the new branch name defaults to the remote branch name with
// the remote stripped off
t.ExpectPopup().Prompt().
Title(Equals("New branch and worktree name")).
InitialText(Equals("feature")).
Confirm()
t.ExpectPopup().Menu().
Title(Equals("Worktree location")).
Confirm()
})
// we've switched into the new worktree, on a local branch that tracks
// the remote one (the ✓ confirms tracking is set up)
t.Views().Branches().
IsFocused().
Lines(
Contains("feature").Contains("✓").IsSelected(),
Contains("master (worktree repo)"),
)
},
})