Skip to content

Commit 0904bf9

Browse files
committed
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.
1 parent 21483b2 commit 0904bf9

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

pkg/integration/components/shell.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ func (self *Shell) Commit(message string) *Shell {
170170
return self.RunCommand([]string{"git", "commit", "-m", message})
171171
}
172172

173+
func (self *Shell) CommitInWorktreeOrSubmodule(worktreePath string, message string) *Shell {
174+
return self.RunCommand([]string{"git", "-C", worktreePath, "commit", "-m", message})
175+
}
176+
173177
func (self *Shell) EmptyCommit(message string) *Shell {
174178
return self.RunCommand([]string{"git", "commit", "--allow-empty", "-m", message})
175179
}
@@ -438,6 +442,16 @@ func (self *Shell) AddFileInWorktreeOrSubmodule(worktreePath string, filePath st
438442
return self
439443
}
440444

445+
func (self *Shell) UpdateFileInWorktreeOrSubmodule(worktreePath string, filePath string, content string) *Shell {
446+
self.UpdateFile(filepath.Join(worktreePath, filePath), content)
447+
448+
self.RunCommand([]string{
449+
"git", "-C", worktreePath, "add", filePath,
450+
})
451+
452+
return self
453+
}
454+
441455
func (self *Shell) MakeExecutable(path string) *Shell {
442456
// 0755 sets the executable permission for owner, and read/execute permissions for group and others
443457
err := os.Chmod(filepath.Join(self.dir, path), 0o755)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package commit
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
)
7+
8+
var DiscardSubmoduleChanges = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Discarding changes to a submodule from an old commit.",
10+
ExtraCmdArgs: []string{},
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {},
13+
SetupRepo: func(shell *Shell) {
14+
shell.EmptyCommit("Initial commit")
15+
shell.CloneIntoSubmodule("submodule", "submodule")
16+
shell.Commit("Add submodule")
17+
18+
shell.AddFileInWorktreeOrSubmodule("submodule", "file", "content")
19+
shell.CommitInWorktreeOrSubmodule("submodule", "add file in submodule")
20+
shell.GitAdd("submodule")
21+
shell.Commit("Update submodule")
22+
23+
shell.UpdateFileInWorktreeOrSubmodule("submodule", "file", "changed content")
24+
shell.CommitInWorktreeOrSubmodule("submodule", "change file in submodule")
25+
shell.GitAdd("submodule")
26+
shell.Commit("Update submodule again")
27+
},
28+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
29+
t.Views().Commits().
30+
Focus().
31+
Lines(
32+
Contains("Update submodule again").IsSelected(),
33+
Contains("Update submodule"),
34+
Contains("Add submodule"),
35+
Contains("Initial commit"),
36+
).
37+
PressEnter()
38+
39+
t.Views().CommitFiles().
40+
IsFocused().
41+
Lines(
42+
Equals("M submodule").IsSelected(),
43+
).
44+
Press(keys.Universal.Remove)
45+
46+
t.ExpectPopup().Confirmation().
47+
Title(Equals("Discard file changes")).
48+
Content(Contains("Are you sure you want to remove changes to the selected file(s) from this commit?")).
49+
Confirm()
50+
51+
t.Shell().RunCommand([]string{"git", "submodule", "update"})
52+
/* EXPECTED:
53+
t.FileSystem().FileContent("submodule/file", Equals("content"))
54+
ACTUAL: */
55+
t.FileSystem().PathNotPresent("submodule/file")
56+
},
57+
})

pkg/integration/tests/test_list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ var tests = []*components.IntegrationTest{
119119
commit.CreateTag,
120120
commit.DisableCopyCommitMessageBody,
121121
commit.DiscardOldFileChanges,
122+
commit.DiscardSubmoduleChanges,
122123
commit.DoNotShowBranchMarkerForHeadCommit,
123124
commit.FailHooksThenCommitNoHooks,
124125
commit.FindBaseCommitForFixup,

0 commit comments

Comments
 (0)