From 245563bc99429b32f88a497845a0be1f6033f3ee Mon Sep 17 00:00:00 2001 From: Nils Andresen Date: Thu, 24 Nov 2022 12:56:03 +0100 Subject: [PATCH 1/2] (#2288) quote remoteName before compiling regex If the remote name contains special regex-chars, the compilation of the regex might fail. Quoting the remoteName ensures that all special chars in the remoteName are properly escaped before compiling the regex. --- pkg/commands/git_commands/remote_loader.go | 2 +- pkg/integration/components/shell.go | 5 ++++ .../tests/config/remote_named_star.go | 26 +++++++++++++++++++ pkg/integration/tests/tests.go | 2 ++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 pkg/integration/tests/config/remote_named_star.go diff --git a/pkg/commands/git_commands/remote_loader.go b/pkg/commands/git_commands/remote_loader.go index 71dc41b80..1b0db49e0 100644 --- a/pkg/commands/git_commands/remote_loader.go +++ b/pkg/commands/git_commands/remote_loader.go @@ -45,7 +45,7 @@ func (self *RemoteLoader) GetRemotes() ([]*models.Remote, error) { remotes := slices.Map(goGitRemotes, func(goGitRemote *gogit.Remote) *models.Remote { remoteName := goGitRemote.Config().Name - re := regexp.MustCompile(fmt.Sprintf(`(?m)^\s*%s\/([\S]+)`, remoteName)) + re := regexp.MustCompile(fmt.Sprintf(`(?m)^\s*%s\/([\S]+)`, regexp.QuoteMeta(remoteName))) matches := re.FindAllStringSubmatch(remoteBranchesStr, -1) branches := slices.Map(matches, func(match []string) *models.RemoteBranch { return &models.RemoteBranch{ diff --git a/pkg/integration/components/shell.go b/pkg/integration/components/shell.go index 95b601783..409a17bc6 100644 --- a/pkg/integration/components/shell.go +++ b/pkg/integration/components/shell.go @@ -125,3 +125,8 @@ func (s *Shell) StashWithMessage(message string) *Shell { s.RunCommand(fmt.Sprintf(`git stash -m "%s"`, message)) return s } + +func (s *Shell) SetConfig(key string, value string) *Shell { + s.RunCommand(fmt.Sprintf(`git config --local "%s" %s`, key, value)) + return s +} diff --git a/pkg/integration/tests/config/remote_named_star.go b/pkg/integration/tests/config/remote_named_star.go new file mode 100644 index 000000000..3082c594f --- /dev/null +++ b/pkg/integration/tests/config/remote_named_star.go @@ -0,0 +1,26 @@ +package config + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var RemoteNamedStar = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Having a config remote.*", + ExtraCmdArgs: "", + Skip: false, + SetupRepo: func(shell *Shell) { + shell. + SetConfig("remote.*.prune", "true"). + CreateNCommits(2) + }, + SetupConfig: func(cfg *config.AppConfig) {}, + Run: func( + shell *Shell, + input *Input, + assert *Assert, + keys config.KeybindingConfig, + ) { + assert.AtLeastOneCommit() + }, +}) diff --git a/pkg/integration/tests/tests.go b/pkg/integration/tests/tests.go index 1ed99a47c..f097b032d 100644 --- a/pkg/integration/tests/tests.go +++ b/pkg/integration/tests/tests.go @@ -14,6 +14,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/integration/tests/branch" "github.com/jesseduffield/lazygit/pkg/integration/tests/cherry_pick" "github.com/jesseduffield/lazygit/pkg/integration/tests/commit" + "github.com/jesseduffield/lazygit/pkg/integration/tests/config" "github.com/jesseduffield/lazygit/pkg/integration/tests/custom_commands" "github.com/jesseduffield/lazygit/pkg/integration/tests/file" "github.com/jesseduffield/lazygit/pkg/integration/tests/interactive_rebase" @@ -45,6 +46,7 @@ var tests = []*components.IntegrationTest{ stash.Rename, stash.Stash, stash.StashIncludingUntrackedFiles, + config.RemoteNamedStar, } func GetTests() []*components.IntegrationTest { From d24feb14e54a686513cbea0f5276faef833fe220 Mon Sep 17 00:00:00 2001 From: Nils Andresen Date: Thu, 24 Nov 2022 13:17:02 +0000 Subject: [PATCH 2/2] added test data --- .../expected/repo/.git_keep/COMMIT_EDITMSG | 1 + .../expected/repo/.git_keep/FETCH_HEAD | 0 .../expected/repo/.git_keep/HEAD | 1 + .../expected/repo/.git_keep/config | 14 ++++++++++++++ .../expected/repo/.git_keep/description | 1 + .../expected/repo/.git_keep/index | Bin 0 -> 225 bytes .../expected/repo/.git_keep/info/exclude | 6 ++++++ .../expected/repo/.git_keep/logs/HEAD | 2 ++ .../repo/.git_keep/logs/refs/heads/master | 2 ++ .../06/47fe4b7302efbfb235b8f0681b592cc3389d36 | Bin 0 -> 30 bytes .../47/d78ad7a27fc7fe483389512ebf7ea34c5514bc | Bin 0 -> 30 bytes .../4f/a4f5e427373ac4ac0a6e11ff97293649959859 | Bin 0 -> 117 bytes .../55/3197193920043fb04f3e39e825916990955204 | Bin 0 -> 55 bytes .../a0/2c4b36b68df7081152282cf1aabcab7b24e69b | Bin 0 -> 81 bytes .../dd/b8365ff4c367dbd7d49b965ab4b43c865b99cf | 2 ++ .../expected/repo/.git_keep/refs/heads/master | 1 + .../remote_named_star/expected/repo/file01.txt | 1 + .../remote_named_star/expected/repo/file02.txt | 1 + 18 files changed, 32 insertions(+) create mode 100644 test/integration_new/config/remote_named_star/expected/repo/.git_keep/COMMIT_EDITMSG create mode 100644 test/integration_new/config/remote_named_star/expected/repo/.git_keep/FETCH_HEAD create mode 100644 test/integration_new/config/remote_named_star/expected/repo/.git_keep/HEAD create mode 100644 test/integration_new/config/remote_named_star/expected/repo/.git_keep/config create mode 100644 test/integration_new/config/remote_named_star/expected/repo/.git_keep/description create mode 100644 test/integration_new/config/remote_named_star/expected/repo/.git_keep/index create mode 100644 test/integration_new/config/remote_named_star/expected/repo/.git_keep/info/exclude create mode 100644 test/integration_new/config/remote_named_star/expected/repo/.git_keep/logs/HEAD create mode 100644 test/integration_new/config/remote_named_star/expected/repo/.git_keep/logs/refs/heads/master create mode 100644 test/integration_new/config/remote_named_star/expected/repo/.git_keep/objects/06/47fe4b7302efbfb235b8f0681b592cc3389d36 create mode 100644 test/integration_new/config/remote_named_star/expected/repo/.git_keep/objects/47/d78ad7a27fc7fe483389512ebf7ea34c5514bc create mode 100644 test/integration_new/config/remote_named_star/expected/repo/.git_keep/objects/4f/a4f5e427373ac4ac0a6e11ff97293649959859 create mode 100644 test/integration_new/config/remote_named_star/expected/repo/.git_keep/objects/55/3197193920043fb04f3e39e825916990955204 create mode 100644 test/integration_new/config/remote_named_star/expected/repo/.git_keep/objects/a0/2c4b36b68df7081152282cf1aabcab7b24e69b create mode 100644 test/integration_new/config/remote_named_star/expected/repo/.git_keep/objects/dd/b8365ff4c367dbd7d49b965ab4b43c865b99cf create mode 100644 test/integration_new/config/remote_named_star/expected/repo/.git_keep/refs/heads/master create mode 100644 test/integration_new/config/remote_named_star/expected/repo/file01.txt create mode 100644 test/integration_new/config/remote_named_star/expected/repo/file02.txt diff --git a/test/integration_new/config/remote_named_star/expected/repo/.git_keep/COMMIT_EDITMSG b/test/integration_new/config/remote_named_star/expected/repo/.git_keep/COMMIT_EDITMSG new file mode 100644 index 000000000..4a78b0618 --- /dev/null +++ b/test/integration_new/config/remote_named_star/expected/repo/.git_keep/COMMIT_EDITMSG @@ -0,0 +1 @@ +commit 02 diff --git a/test/integration_new/config/remote_named_star/expected/repo/.git_keep/FETCH_HEAD b/test/integration_new/config/remote_named_star/expected/repo/.git_keep/FETCH_HEAD new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration_new/config/remote_named_star/expected/repo/.git_keep/HEAD b/test/integration_new/config/remote_named_star/expected/repo/.git_keep/HEAD new file mode 100644 index 000000000..cb089cd89 --- /dev/null +++ b/test/integration_new/config/remote_named_star/expected/repo/.git_keep/HEAD @@ -0,0 +1 @@ +ref: refs/heads/master diff --git a/test/integration_new/config/remote_named_star/expected/repo/.git_keep/config b/test/integration_new/config/remote_named_star/expected/repo/.git_keep/config new file mode 100644 index 000000000..b485809ad --- /dev/null +++ b/test/integration_new/config/remote_named_star/expected/repo/.git_keep/config @@ -0,0 +1,14 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = false + logallrefupdates = true +[user] + email = CI@example.com + name = CI +[commit] + gpgSign = false +[protocol "file"] + allow = always +[remote "*"] + prune = true diff --git a/test/integration_new/config/remote_named_star/expected/repo/.git_keep/description b/test/integration_new/config/remote_named_star/expected/repo/.git_keep/description new file mode 100644 index 000000000..498b267a8 --- /dev/null +++ b/test/integration_new/config/remote_named_star/expected/repo/.git_keep/description @@ -0,0 +1 @@ +Unnamed repository; edit this file 'description' to name the repository. diff --git a/test/integration_new/config/remote_named_star/expected/repo/.git_keep/index b/test/integration_new/config/remote_named_star/expected/repo/.git_keep/index new file mode 100644 index 0000000000000000000000000000000000000000..3931f762e225cd127ae48c0e900dbcc1280e6394 GIT binary patch literal 225 zcmZ?q402{*U|<5_ 1669295719 +0000 commit (initial): commit 01 +4fa4f5e427373ac4ac0a6e11ff97293649959859 ddb8365ff4c367dbd7d49b965ab4b43c865b99cf CI 1669295719 +0000 commit: commit 02 diff --git a/test/integration_new/config/remote_named_star/expected/repo/.git_keep/logs/refs/heads/master b/test/integration_new/config/remote_named_star/expected/repo/.git_keep/logs/refs/heads/master new file mode 100644 index 000000000..d1a05666d --- /dev/null +++ b/test/integration_new/config/remote_named_star/expected/repo/.git_keep/logs/refs/heads/master @@ -0,0 +1,2 @@ +0000000000000000000000000000000000000000 4fa4f5e427373ac4ac0a6e11ff97293649959859 CI 1669295719 +0000 commit (initial): commit 01 +4fa4f5e427373ac4ac0a6e11ff97293649959859 ddb8365ff4c367dbd7d49b965ab4b43c865b99cf CI 1669295719 +0000 commit: commit 02 diff --git a/test/integration_new/config/remote_named_star/expected/repo/.git_keep/objects/06/47fe4b7302efbfb235b8f0681b592cc3389d36 b/test/integration_new/config/remote_named_star/expected/repo/.git_keep/objects/06/47fe4b7302efbfb235b8f0681b592cc3389d36 new file mode 100644 index 0000000000000000000000000000000000000000..a8a2b586df771ca14cecde7807a27ce30a6b580c GIT binary patch literal 30 mcmb+k8|g>J5cLD&o#S2XU literal 0 HcmV?d00001 diff --git a/test/integration_new/config/remote_named_star/expected/repo/.git_keep/objects/47/d78ad7a27fc7fe483389512ebf7ea34c5514bc b/test/integration_new/config/remote_named_star/expected/repo/.git_keep/objects/47/d78ad7a27fc7fe483389512ebf7ea34c5514bc new file mode 100644 index 0000000000000000000000000000000000000000..c562d38cc74cf217a96352f3dc336a387371e749 GIT binary patch literal 30 mcmbsk8|g>JrT^5<1}CWvy|7$%4di(1Z N`-F<@0RUnl5mQh97fApB literal 0 HcmV?d00001 diff --git a/test/integration_new/config/remote_named_star/expected/repo/.git_keep/objects/a0/2c4b36b68df7081152282cf1aabcab7b24e69b b/test/integration_new/config/remote_named_star/expected/repo/.git_keep/objects/a0/2c4b36b68df7081152282cf1aabcab7b24e69b new file mode 100644 index 0000000000000000000000000000000000000000..85866acd897b150150557b0a331c827562ca4fa7 GIT binary patch literal 81 zcmV-X0IvUd0V^p=O;s>AV=y!@Ff%bxNXyJgH89jGsVHG^zut9yQT_3M9>$%4di(1Z n`-F<@K~`l1R>kK2&%2oE{r*j+J3eGcN9r85m}>?A;$I(9i#8>| literal 0 HcmV?d00001 diff --git a/test/integration_new/config/remote_named_star/expected/repo/.git_keep/objects/dd/b8365ff4c367dbd7d49b965ab4b43c865b99cf b/test/integration_new/config/remote_named_star/expected/repo/.git_keep/objects/dd/b8365ff4c367dbd7d49b965ab4b43c865b99cf new file mode 100644 index 000000000..fc4abfe75 --- /dev/null +++ b/test/integration_new/config/remote_named_star/expected/repo/.git_keep/objects/dd/b8365ff4c367dbd7d49b965ab4b43c865b99cf @@ -0,0 +1,2 @@ +x; +1@sL"V{I`e+^]z @XXbd3b T*%U6} M| )zV"ƉE86ei4_#}}.# GcvO 3`|O: \ No newline at end of file diff --git a/test/integration_new/config/remote_named_star/expected/repo/.git_keep/refs/heads/master b/test/integration_new/config/remote_named_star/expected/repo/.git_keep/refs/heads/master new file mode 100644 index 000000000..4dcaa7e6b --- /dev/null +++ b/test/integration_new/config/remote_named_star/expected/repo/.git_keep/refs/heads/master @@ -0,0 +1 @@ +ddb8365ff4c367dbd7d49b965ab4b43c865b99cf diff --git a/test/integration_new/config/remote_named_star/expected/repo/file01.txt b/test/integration_new/config/remote_named_star/expected/repo/file01.txt new file mode 100644 index 000000000..47d78ad7a --- /dev/null +++ b/test/integration_new/config/remote_named_star/expected/repo/file01.txt @@ -0,0 +1 @@ +file01 content \ No newline at end of file diff --git a/test/integration_new/config/remote_named_star/expected/repo/file02.txt b/test/integration_new/config/remote_named_star/expected/repo/file02.txt new file mode 100644 index 000000000..0647fe4b7 --- /dev/null +++ b/test/integration_new/config/remote_named_star/expected/repo/file02.txt @@ -0,0 +1 @@ +file02 content \ No newline at end of file