summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorNils Andresen <nils@nils-andresen.de>2022-11-24 12:56:03 +0100
committerNils Andresen <nils@nils-andresen.de>2022-11-24 12:56:28 +0000
commit245563bc99429b32f88a497845a0be1f6033f3ee (patch)
tree5e43c54791a710334b114c7923e0fdb70ae165b0 /pkg
parent924a152ae92372a178bd0fc32b411612b995a6a1 (diff)
(#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.
Diffstat (limited to 'pkg')
-rw-r--r--pkg/commands/git_commands/remote_loader.go2
-rw-r--r--pkg/integration/components/shell.go5
-rw-r--r--pkg/integration/tests/config/remote_named_star.go26
-rw-r--r--pkg/integration/tests/tests.go2
4 files changed, 34 insertions, 1 deletions
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 {