From 85a6a42bff05c38d0485ff40ce064145604c661b Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 10 Feb 2024 19:42:30 +0100 Subject: [PATCH] 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. --- pkg/integration/components/git.go | 11 +++++++++++ pkg/integration/components/shell.go | 4 ++-- pkg/integration/tests/submodule/enter.go | 12 ++++++++---- pkg/integration/tests/submodule/remove.go | 12 ++++++------ pkg/integration/tests/submodule/reset.go | 22 ++++++++++++---------- 5 files changed, 39 insertions(+), 22 deletions(-) diff --git a/pkg/integration/components/git.go b/pkg/integration/components/git.go index ed327b3ed..1e2975be2 100644 --- a/pkg/integration/components/git.go +++ b/pkg/integration/components/git.go @@ -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 +} diff --git a/pkg/integration/components/shell.go b/pkg/integration/components/shell.go index 48ff3fdf7..60c627918 100644 --- a/pkg/integration/components/shell.go +++ b/pkg/integration/components/shell.go @@ -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 } diff --git a/pkg/integration/tests/submodule/enter.go b/pkg/integration/tests/submodule/enter.go index 7b055c2b6..29e983b7f 100644 --- a/pkg/integration/tests/submodule/enter.go +++ b/pkg/integration/tests/submodule/enter.go @@ -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 diff --git a/pkg/integration/tests/submodule/remove.go b/pkg/integration/tests/submodule/remove.go index 3d85d4d5c..886eb6294 100644 --- a/pkg/integration/tests/submodule/remove.go +++ b/pkg/integration/tests/submodule/remove.go @@ -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"), ) }, diff --git a/pkg/integration/tests/submodule/reset.go b/pkg/integration/tests/submodule/reset.go index fba91bee8..a723561fc 100644 --- a/pkg/integration/tests/submodule/reset.go +++ b/pkg/integration/tests/submodule/reset.go @@ -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() }).