Skip to content

Commit f1b0ca4

Browse files
committed
Offer to force-delete a worktree if it contains submodules
1 parent 59fdc9c commit f1b0ca4

File tree

5 files changed

+5
-16
lines changed

5 files changed

+5
-16
lines changed

pkg/gui/controllers/helpers/worktree_helper.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ func (self *WorktreeHelper) Remove(worktree *models.Worktree, force bool) error
189189
self.c.LogAction(self.c.Tr.RemoveWorktree)
190190
if err := self.c.Git().Worktree.Delete(worktree.Path, force); err != nil {
191191
errMessage := err.Error()
192-
if !strings.Contains(errMessage, "--force") {
192+
if !strings.Contains(errMessage, "--force") &&
193+
!strings.Contains(errMessage, "fatal: working trees containing submodules cannot be moved or removed") {
193194
return err
194195
}
195196

pkg/i18n/english.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1927,7 +1927,7 @@ func EnglishTranslationSet() *TranslationSet {
19271927
RemoveWorktree: "Remove worktree",
19281928
RemoveWorktreeTitle: "Remove worktree",
19291929
RemoveWorktreePrompt: "Are you sure you want to remove worktree '{{.worktreeName}}'?",
1930-
ForceRemoveWorktreePrompt: "'{{.worktreeName}}' contains modified or untracked files (to be honest, it could contain both). Are you sure you want to remove it?",
1930+
ForceRemoveWorktreePrompt: "'{{.worktreeName}}' contains modified or untracked files, or submodules (or all of these). Are you sure you want to remove it?",
19311931
RemovingWorktree: "Deleting worktree",
19321932
DetachWorktree: "Detach worktree",
19331933
DetachingWorktree: "Detaching worktree",

pkg/integration/tests/worktree/force_remove_worktree.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var ForceRemoveWorktree = NewIntegrationTest(NewIntegrationTestArgs{
3636

3737
t.ExpectPopup().Confirmation().
3838
Title(Equals("Remove worktree")).
39-
Content(Equals("'linked-worktree' contains modified or untracked files (to be honest, it could contain both). Are you sure you want to remove it?")).
39+
Content(Equals("'linked-worktree' contains modified or untracked files, or submodules (or all of these). Are you sure you want to remove it?")).
4040
Confirm()
4141
}).
4242
Lines(

pkg/integration/tests/worktree/force_remove_worktree_with_submodules.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,13 @@ var ForceRemoveWorktreeWithSubmodules = NewIntegrationTest(NewIntegrationTestArg
3434
Content(Equals("Are you sure you want to remove worktree 'linked-worktree'?")).
3535
Confirm()
3636

37-
/* EXPECTED:
3837
t.ExpectPopup().Confirmation().
3938
Title(Equals("Remove worktree")).
4039
Content(Equals("'linked-worktree' contains modified or untracked files, or submodules (or all of these). Are you sure you want to remove it?")).
4140
Confirm()
42-
ACTUAL: */
43-
t.ExpectPopup().Alert().
44-
Title(Equals("Error")).
45-
Content(Equals("fatal: working trees containing submodules cannot be moved or removed")).
46-
Confirm()
4741
}).
48-
/* EXPECTED:
4942
Lines(
5043
Contains("repo (main)").IsSelected(),
5144
)
52-
ACTUAL: */
53-
Lines(
54-
Contains("repo (main)"),
55-
Contains("linked-worktree").IsSelected(),
56-
)
5745
},
5846
})

pkg/integration/tests/worktree/remove_worktree_from_branch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ var RemoveWorktreeFromBranch = NewIntegrationTest(NewIntegrationTestArgs{
4848

4949
t.ExpectPopup().Confirmation().
5050
Title(Equals("Remove worktree")).
51-
Content(Equals("'linked-worktree' contains modified or untracked files (to be honest, it could contain both). Are you sure you want to remove it?")).
51+
Content(Equals("'linked-worktree' contains modified or untracked files, or submodules (or all of these). Are you sure you want to remove it?")).
5252
Confirm()
5353
}).
5454
Lines(

0 commit comments

Comments
 (0)