1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-10-08 22:52:12 +02:00

Add test demonstrating the problem

When dropping changes to the submodule, we expect it to get rolled back to the
previous version; however, it is removed entirely instead.
This commit is contained in:
Stefan Haller
2025-10-05 14:52:28 +02:00
parent 5b9331f42c
commit 9488dc2c98
3 changed files with 72 additions and 0 deletions

View File

@@ -170,6 +170,10 @@ func (self *Shell) Commit(message string) *Shell {
return self.RunCommand([]string{"git", "commit", "-m", message}) return self.RunCommand([]string{"git", "commit", "-m", message})
} }
func (self *Shell) CommitInWorktreeOrSubmodule(worktreePath string, message string) *Shell {
return self.RunCommand([]string{"git", "-C", worktreePath, "commit", "-m", message})
}
func (self *Shell) EmptyCommit(message string) *Shell { func (self *Shell) EmptyCommit(message string) *Shell {
return self.RunCommand([]string{"git", "commit", "--allow-empty", "-m", message}) return self.RunCommand([]string{"git", "commit", "--allow-empty", "-m", message})
} }
@@ -438,6 +442,16 @@ func (self *Shell) AddFileInWorktreeOrSubmodule(worktreePath string, filePath st
return self return self
} }
func (self *Shell) UpdateFileInWorktreeOrSubmodule(worktreePath string, filePath string, content string) *Shell {
self.UpdateFile(filepath.Join(worktreePath, filePath), content)
self.RunCommand([]string{
"git", "-C", worktreePath, "add", filePath,
})
return self
}
func (self *Shell) MakeExecutable(path string) *Shell { func (self *Shell) MakeExecutable(path string) *Shell {
// 0755 sets the executable permission for owner, and read/execute permissions for group and others // 0755 sets the executable permission for owner, and read/execute permissions for group and others
err := os.Chmod(filepath.Join(self.dir, path), 0o755) err := os.Chmod(filepath.Join(self.dir, path), 0o755)

View File

@@ -0,0 +1,57 @@
package commit
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var DiscardSubmoduleChanges = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Discarding changes to a submodule from an old commit.",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.EmptyCommit("Initial commit")
shell.CloneIntoSubmodule("submodule", "submodule")
shell.Commit("Add submodule")
shell.AddFileInWorktreeOrSubmodule("submodule", "file", "content")
shell.CommitInWorktreeOrSubmodule("submodule", "add file in submodule")
shell.GitAdd("submodule")
shell.Commit("Update submodule")
shell.UpdateFileInWorktreeOrSubmodule("submodule", "file", "changed content")
shell.CommitInWorktreeOrSubmodule("submodule", "change file in submodule")
shell.GitAdd("submodule")
shell.Commit("Update submodule again")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Lines(
Contains("Update submodule again").IsSelected(),
Contains("Update submodule"),
Contains("Add submodule"),
Contains("Initial commit"),
).
PressEnter()
t.Views().CommitFiles().
IsFocused().
Lines(
Equals("M submodule").IsSelected(),
).
Press(keys.Universal.Remove)
t.ExpectPopup().Confirmation().
Title(Equals("Discard file changes")).
Content(Contains("Are you sure you want to remove changes to the selected file(s) from this commit?")).
Confirm()
t.Shell().RunCommand([]string{"git", "submodule", "update"})
/* EXPECTED:
t.FileSystem().FileContent("submodule/file", Equals("content"))
ACTUAL: */
t.FileSystem().PathNotPresent("submodule/file")
},
})

View File

@@ -119,6 +119,7 @@ var tests = []*components.IntegrationTest{
commit.CreateTag, commit.CreateTag,
commit.DisableCopyCommitMessageBody, commit.DisableCopyCommitMessageBody,
commit.DiscardOldFileChanges, commit.DiscardOldFileChanges,
commit.DiscardSubmoduleChanges,
commit.DoNotShowBranchMarkerForHeadCommit, commit.DoNotShowBranchMarkerForHeadCommit,
commit.FailHooksThenCommitNoHooks, commit.FailHooksThenCommitNoHooks,
commit.FindBaseCommitForFixup, commit.FindBaseCommitForFixup,