mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 15:46:26 -04:00
Pressing `d` on a worktree only ever removed the worktree, leaving its branch behind even though deleting it too is often what you want. Turn the confirmation into a menu: "Remove worktree", "Remove worktree and delete branch", and "Remove worktree and delete local and remote branch". The branch-deleting items come after the plain removal (they do more harm if picked by accident); both are greyed out for a detached-HEAD worktree, and the local-and-remote one is also greyed when the branch has no upstream. The plain menu pick is the confirmation, so the standalone "remove worktree?" prompt is gone (and its now-dead translation string with it); the dirty-worktree force prompt and the unmerged-branch warning still appear when relevant. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
119 lines
2.9 KiB
Go
119 lines
2.9 KiB
Go
package worktree
|
|
|
|
import (
|
|
"github.com/jesseduffield/lazygit/pkg/config"
|
|
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
|
)
|
|
|
|
var Crud = NewIntegrationTest(NewIntegrationTestArgs{
|
|
Description: "From the worktrees view, add a work tree, switch to it, switch back, and remove it",
|
|
ExtraCmdArgs: []string{},
|
|
Skip: false,
|
|
SetupConfig: func(config *config.AppConfig) {},
|
|
SetupRepo: func(shell *Shell) {
|
|
shell.NewBranch("mybranch")
|
|
shell.CreateFileAndAdd("README.md", "hello world")
|
|
shell.Commit("initial commit")
|
|
},
|
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
|
t.Views().Branches().
|
|
Lines(
|
|
Contains("mybranch"),
|
|
)
|
|
|
|
t.Views().Status().
|
|
Lines(
|
|
Contains("repo → mybranch"),
|
|
)
|
|
|
|
t.Views().Worktrees().
|
|
Focus().
|
|
Lines(
|
|
Contains("(main worktree)"),
|
|
).
|
|
Press(keys.Universal.New).
|
|
Tap(func() {
|
|
// a name that isn't an existing branch creates a new branch off
|
|
// the current one
|
|
t.ExpectPopup().Prompt().
|
|
Title(Equals("New worktree for branch")).
|
|
Type("newbranch").
|
|
Confirm()
|
|
|
|
t.ExpectPopup().Menu().
|
|
Title(Equals("Worktree location")).
|
|
Select(Contains("Other…")).
|
|
Confirm()
|
|
|
|
t.ExpectPopup().Prompt().
|
|
Title(Equals("New worktree path")).
|
|
Clear().
|
|
Type("../linked-worktree").
|
|
Confirm()
|
|
}).
|
|
Lines(
|
|
Contains("linked-worktree").IsSelected(),
|
|
Contains("(main worktree)"),
|
|
).
|
|
// confirm we're still in the same view
|
|
IsFocused()
|
|
|
|
// status panel includes the worktree if it's a linked worktree
|
|
t.Views().Status().
|
|
Lines(
|
|
Contains("repo(linked-worktree) → newbranch"),
|
|
)
|
|
|
|
t.Views().Branches().
|
|
Lines(
|
|
Contains("newbranch"),
|
|
Contains("mybranch"),
|
|
)
|
|
|
|
t.Views().Worktrees().
|
|
// confirm we can't remove the current worktree
|
|
Press(keys.Universal.Remove).
|
|
Tap(func() {
|
|
t.ExpectPopup().Alert().
|
|
Title(Equals("Error")).
|
|
Content(Equals("You cannot remove the current worktree!")).
|
|
Confirm()
|
|
}).
|
|
// confirm we cannot remove the main worktree
|
|
NavigateToLine(Contains("(main worktree)")).
|
|
Press(keys.Universal.Remove).
|
|
Tap(func() {
|
|
t.ExpectPopup().Alert().
|
|
Title(Equals("Error")).
|
|
Content(Equals("You cannot remove the main worktree!")).
|
|
Confirm()
|
|
}).
|
|
// switch back to main worktree
|
|
Press(keys.Universal.Select).
|
|
Lines(
|
|
Contains("(main worktree)").IsSelected(),
|
|
Contains("linked-worktree"),
|
|
)
|
|
|
|
t.Views().Branches().
|
|
Lines(
|
|
Contains("mybranch"),
|
|
Contains("newbranch"),
|
|
)
|
|
|
|
t.Views().Worktrees().
|
|
// remove linked worktree
|
|
NavigateToLine(Contains("linked-worktree")).
|
|
Press(keys.Universal.Remove).
|
|
Tap(func() {
|
|
t.ExpectPopup().Menu().
|
|
Title(Equals("Remove worktree 'linked-worktree'?")).
|
|
Select(MatchesRegexp("Remove worktree$")).
|
|
Confirm()
|
|
}).
|
|
Lines(
|
|
Contains("(main worktree)").IsSelected(),
|
|
)
|
|
},
|
|
})
|