mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-30 03:23:08 +03:00
Extend submodule tests to use a submodule where name and path are different
In most real-world scenarios, name and path are usually the same. They don't have to be though, and it's important to make sure we use the right one when passing arguments to git commands, so change the tests to have different name and path.
This commit is contained in:
@ -2,7 +2,10 @@ package components
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
||||
)
|
||||
|
||||
type Git struct {
|
||||
@ -44,3 +47,11 @@ func (self *Git) expect(cmdArgs []string, condition func(string) (bool, string))
|
||||
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *Git) Version() *git_commands.GitVersion {
|
||||
version, err := getGitVersion()
|
||||
if err != nil {
|
||||
log.Fatalf("Could not get git version: %v", err)
|
||||
}
|
||||
return version
|
||||
}
|
||||
|
@ -345,9 +345,9 @@ func (self *Shell) CloneIntoRemote(name string) *Shell {
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *Shell) CloneIntoSubmodule(submoduleName string) *Shell {
|
||||
func (self *Shell) CloneIntoSubmodule(submoduleName string, submodulePath string) *Shell {
|
||||
self.Clone("other_repo")
|
||||
self.RunCommand([]string{"git", "submodule", "add", "../other_repo", submoduleName})
|
||||
self.RunCommand([]string{"git", "submodule", "add", "--name", submoduleName, "../other_repo", submodulePath})
|
||||
|
||||
return self
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ var Enter = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
},
|
||||
SetupRepo: func(shell *Shell) {
|
||||
shell.EmptyCommit("first commit")
|
||||
shell.CloneIntoSubmodule("my_submodule")
|
||||
shell.CloneIntoSubmodule("my_submodule_name", "my_submodule_path")
|
||||
shell.GitAddAll()
|
||||
shell.Commit("add submodule")
|
||||
},
|
||||
@ -29,14 +29,18 @@ var Enter = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
t.Views().Status().Content(Contains("repo"))
|
||||
}
|
||||
assertInSubmodule := func() {
|
||||
t.Views().Status().Content(Contains("my_submodule"))
|
||||
if t.Git().Version().IsAtLeast(2, 22, 0) {
|
||||
t.Views().Status().Content(Contains("my_submodule_path(my_submodule_name)"))
|
||||
} else {
|
||||
t.Views().Status().Content(Contains("my_submodule_path"))
|
||||
}
|
||||
}
|
||||
|
||||
assertInParentRepo()
|
||||
|
||||
t.Views().Submodules().Focus().
|
||||
Lines(
|
||||
Contains("my_submodule").IsSelected(),
|
||||
Contains("my_submodule_name").IsSelected(),
|
||||
).
|
||||
// enter the submodule
|
||||
PressEnter()
|
||||
@ -60,7 +64,7 @@ var Enter = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
|
||||
t.Views().Files().Focus().
|
||||
Lines(
|
||||
MatchesRegexp(` M.*my_submodule \(submodule\)`).IsSelected(),
|
||||
MatchesRegexp(` M.*my_submodule_path \(submodule\)`).IsSelected(),
|
||||
).
|
||||
Tap(func() {
|
||||
// main view also shows the new commit when we're looking at the submodule within the files view
|
||||
|
@ -12,20 +12,20 @@ var Remove = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
SetupConfig: func(config *config.AppConfig) {},
|
||||
SetupRepo: func(shell *Shell) {
|
||||
shell.EmptyCommit("first commit")
|
||||
shell.CloneIntoSubmodule("my_submodule")
|
||||
shell.CloneIntoSubmodule("my_submodule_name", "my_submodule_path")
|
||||
shell.GitAddAll()
|
||||
shell.Commit("add submodule")
|
||||
},
|
||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||
t.Views().Submodules().Focus().
|
||||
Lines(
|
||||
Contains("my_submodule").IsSelected(),
|
||||
Contains("my_submodule_name").IsSelected(),
|
||||
).
|
||||
Press(keys.Universal.Remove).
|
||||
Tap(func() {
|
||||
t.ExpectPopup().Confirmation().
|
||||
Title(Equals("Remove submodule")).
|
||||
Content(Equals("Are you sure you want to remove submodule 'my_submodule' and its corresponding directory? This is irreversible.")).
|
||||
Content(Equals("Are you sure you want to remove submodule 'my_submodule_name' and its corresponding directory? This is irreversible.")).
|
||||
Confirm()
|
||||
}).
|
||||
IsEmpty()
|
||||
@ -33,12 +33,12 @@ var Remove = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
t.Views().Files().Focus().
|
||||
Lines(
|
||||
MatchesRegexp(`M.*\.gitmodules`).IsSelected(),
|
||||
MatchesRegexp(`D.*my_submodule`),
|
||||
MatchesRegexp(`D.*my_submodule_path`),
|
||||
)
|
||||
|
||||
t.Views().Main().Content(
|
||||
Contains("-[submodule \"my_submodule\"]").
|
||||
Contains("- path = my_submodule").
|
||||
Contains("-[submodule \"my_submodule_name\"]").
|
||||
Contains("- path = my_submodule_path").
|
||||
Contains("- url = ../other_repo"),
|
||||
)
|
||||
},
|
||||
|
@ -20,7 +20,7 @@ var Reset = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
},
|
||||
SetupRepo: func(shell *Shell) {
|
||||
shell.EmptyCommit("first commit")
|
||||
shell.CloneIntoSubmodule("my_submodule")
|
||||
shell.CloneIntoSubmodule("my_submodule_name", "my_submodule_path")
|
||||
shell.GitAddAll()
|
||||
shell.Commit("add submodule")
|
||||
|
||||
@ -31,22 +31,24 @@ var Reset = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
t.Views().Status().Content(Contains("repo"))
|
||||
}
|
||||
assertInSubmodule := func() {
|
||||
t.Views().Status().Content(Contains("my_submodule"))
|
||||
if t.Git().Version().IsAtLeast(2, 22, 0) {
|
||||
t.Views().Status().Content(Contains("my_submodule_path(my_submodule_name)"))
|
||||
} else {
|
||||
t.Views().Status().Content(Contains("my_submodule_path"))
|
||||
}
|
||||
}
|
||||
|
||||
assertInParentRepo()
|
||||
|
||||
t.Views().Submodules().Focus().
|
||||
Lines(
|
||||
Contains("my_submodule").IsSelected(),
|
||||
Contains("my_submodule_name").IsSelected(),
|
||||
).
|
||||
// enter the submodule
|
||||
PressEnter()
|
||||
|
||||
assertInSubmodule()
|
||||
|
||||
t.Views().Status().Content(Contains("my_submodule"))
|
||||
|
||||
t.Views().Files().IsFocused().
|
||||
Press("e").
|
||||
Tap(func() {
|
||||
@ -65,18 +67,18 @@ var Reset = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
|
||||
t.Views().Submodules().IsFocused()
|
||||
|
||||
t.Views().Main().Content(Contains("Submodule my_submodule contains modified content"))
|
||||
t.Views().Main().Content(Contains("Submodule my_submodule_path contains modified content"))
|
||||
|
||||
t.Views().Files().Focus().
|
||||
Lines(
|
||||
MatchesRegexp(` M.*my_submodule \(submodule\)`),
|
||||
MatchesRegexp(` M.*my_submodule_path \(submodule\)`),
|
||||
Contains("other_file").IsSelected(),
|
||||
).
|
||||
// Verify we can't use range select on submodules
|
||||
Press(keys.Universal.ToggleRangeSelect).
|
||||
SelectPreviousItem().
|
||||
Lines(
|
||||
MatchesRegexp(` M.*my_submodule \(submodule\)`).IsSelected(),
|
||||
MatchesRegexp(` M.*my_submodule_path \(submodule\)`).IsSelected(),
|
||||
Contains("other_file").IsSelected(),
|
||||
).
|
||||
Press(keys.Universal.Remove).
|
||||
@ -85,13 +87,13 @@ var Reset = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
}).
|
||||
Press(keys.Universal.ToggleRangeSelect).
|
||||
Lines(
|
||||
MatchesRegexp(` M.*my_submodule \(submodule\)`).IsSelected(),
|
||||
MatchesRegexp(` M.*my_submodule_path \(submodule\)`).IsSelected(),
|
||||
Contains("other_file"),
|
||||
).
|
||||
Press(keys.Universal.Remove).
|
||||
Tap(func() {
|
||||
t.ExpectPopup().Menu().
|
||||
Title(Equals("my_submodule")).
|
||||
Title(Equals("my_submodule_path")).
|
||||
Select(Contains("Stash uncommitted submodule changes and update")).
|
||||
Confirm()
|
||||
}).
|
||||
|
Reference in New Issue
Block a user