Add a test for discarding the directory of a removed submodule

If a commit that you check out or pull removes a submodule, git leaves
the submodule's directory behind, and git status reports it as an
untracked directory. The files panel shows that directory with a file
below it that has no name. Discarding the directory shows an error,
even though the directory is gone afterwards.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Stefan Haller
2026-10-15 09:09:49 +02:00
co-authored by Claude Opus 5.5
parent a0fa1becdb
commit 165b4bb499
2 changed files with 57 additions and 0 deletions
@@ -0,0 +1,56 @@
package submodule
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var DiscardRemovedSubmodule = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Discard the directory that a removed submodule leaves behind",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.EmptyCommit("first commit")
shell.CloneIntoSubmodule("sub", "modules/sub")
shell.Commit("add submodule")
// This is what checking out a commit that removes the submodule does:
// the submodule is gone from the index and from .gitmodules, but git
// leaves its directory behind.
shell.RunCommand([]string{"git", "rm", "--cached", "modules/sub"})
shell.RunCommand([]string{"git", "rm", ".gitmodules"})
shell.Commit("remove submodule")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Files().
IsFocused().
Lines(
/* EXPECTED:
Equals("▼ modules").IsSelected(),
Equals(" ?? sub"),
ACTUAL: */
Equals("▼ modules/sub").IsSelected(),
Equals(" ?? "),
).
Press(keys.Universal.Remove).
Tap(func() {
t.ExpectPopup().Menu().
Title(Equals("Discard changes")).
Select(Contains("Discard all changes")).
Confirm()
}).
/* EXPECTED:
IsFocused().
ACTUAL: */
Tap(func() {
t.ExpectPopup().Alert().
Title(Equals("Error")).
Content(Equals("open modules/sub: no such file or directory")).
Confirm()
}).
IsEmpty()
t.FileSystem().PathNotPresent("modules/sub")
},
})
+1
View File
@@ -569,6 +569,7 @@ var tests = []*components.IntegrationTest{
status.LogCmd,
status.LogCmdStatusPanelAllBranchesLog,
submodule.Add,
submodule.DiscardRemovedSubmodule,
submodule.Enter,
submodule.EnterFromDotfileBareRepo,
submodule.EnterNested,