mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-11-23 22:24:51 +02:00
Offer to force-delete a worktree if it contains submodules (#4959)
For a worktree that contains submodules, trying to delete it would show an error instead of offering to force-remove it. Fixes #4125.
This commit is contained in:
@@ -189,7 +189,8 @@ func (self *WorktreeHelper) Remove(worktree *models.Worktree, force bool) error
|
||||
self.c.LogAction(self.c.Tr.RemoveWorktree)
|
||||
if err := self.c.Git().Worktree.Delete(worktree.Path, force); err != nil {
|
||||
errMessage := err.Error()
|
||||
if !strings.Contains(errMessage, "--force") {
|
||||
if !strings.Contains(errMessage, "--force") &&
|
||||
!strings.Contains(errMessage, "fatal: working trees containing submodules cannot be moved or removed") {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -1933,7 +1933,7 @@ func EnglishTranslationSet() *TranslationSet {
|
||||
RemoveWorktree: "Remove worktree",
|
||||
RemoveWorktreeTitle: "Remove worktree",
|
||||
RemoveWorktreePrompt: "Are you sure you want to remove worktree '{{.worktreeName}}'?",
|
||||
ForceRemoveWorktreePrompt: "'{{.worktreeName}}' contains modified or untracked files (to be honest, it could contain both). Are you sure you want to remove it?",
|
||||
ForceRemoveWorktreePrompt: "'{{.worktreeName}}' contains modified or untracked files, or submodules (or all of these). Are you sure you want to remove it?",
|
||||
RemovingWorktree: "Deleting worktree",
|
||||
DetachWorktree: "Detach worktree",
|
||||
DetachingWorktree: "Detaching worktree",
|
||||
|
||||
@@ -455,6 +455,7 @@ var tests = []*components.IntegrationTest{
|
||||
worktree.FastForwardWorktreeBranch,
|
||||
worktree.FastForwardWorktreeBranchShouldNotPolluteCurrentWorktree,
|
||||
worktree.ForceRemoveWorktree,
|
||||
worktree.ForceRemoveWorktreeWithSubmodules,
|
||||
worktree.RemoveWorktreeFromBranch,
|
||||
worktree.ResetWindowTabs,
|
||||
worktree.SymlinkIntoRepoSubdir,
|
||||
|
||||
@@ -36,7 +36,7 @@ var ForceRemoveWorktree = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
|
||||
t.ExpectPopup().Confirmation().
|
||||
Title(Equals("Remove worktree")).
|
||||
Content(Equals("'linked-worktree' contains modified or untracked files (to be honest, it could contain both). Are you sure you want to remove it?")).
|
||||
Content(Equals("'linked-worktree' contains modified or untracked files, or submodules (or all of these). Are you sure you want to remove it?")).
|
||||
Confirm()
|
||||
}).
|
||||
Lines(
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package worktree
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
||||
)
|
||||
|
||||
var ForceRemoveWorktreeWithSubmodules = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
Description: "Force remove a worktree that contains submodules",
|
||||
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")
|
||||
shell.CloneIntoSubmodule("submodule", "submodule")
|
||||
shell.Commit("Add submodule")
|
||||
shell.AddWorktree("mybranch", "../linked-worktree", "newbranch")
|
||||
shell.RunCommand([]string{"git", "-C", "../linked-worktree", "submodule", "update", "--init"})
|
||||
},
|
||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||
t.Views().Worktrees().
|
||||
Focus().
|
||||
Lines(
|
||||
Contains("repo (main)").IsSelected(),
|
||||
Contains("linked-worktree"),
|
||||
).
|
||||
NavigateToLine(Contains("linked-worktree")).
|
||||
Press(keys.Universal.Remove).
|
||||
Tap(func() {
|
||||
t.ExpectPopup().Confirmation().
|
||||
Title(Equals("Remove worktree")).
|
||||
Content(Equals("Are you sure you want to remove worktree 'linked-worktree'?")).
|
||||
Confirm()
|
||||
|
||||
t.ExpectPopup().Confirmation().
|
||||
Title(Equals("Remove worktree")).
|
||||
Content(Equals("'linked-worktree' contains modified or untracked files, or submodules (or all of these). Are you sure you want to remove it?")).
|
||||
Confirm()
|
||||
}).
|
||||
Lines(
|
||||
Contains("repo (main)").IsSelected(),
|
||||
)
|
||||
},
|
||||
})
|
||||
@@ -48,7 +48,7 @@ var RemoveWorktreeFromBranch = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
|
||||
t.ExpectPopup().Confirmation().
|
||||
Title(Equals("Remove worktree")).
|
||||
Content(Equals("'linked-worktree' contains modified or untracked files (to be honest, it could contain both). Are you sure you want to remove it?")).
|
||||
Content(Equals("'linked-worktree' contains modified or untracked files, or submodules (or all of these). Are you sure you want to remove it?")).
|
||||
Confirm()
|
||||
}).
|
||||
Lines(
|
||||
|
||||
Reference in New Issue
Block a user