From 0280c0aeda0cababd8bca74b0c5f7bec3409353d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Baru=C4=8Di=C4=87?= Date: Fri, 2 Sep 2022 11:39:40 +0200 Subject: [PATCH] LibGit2: correct regex for credential helpers The previous regex for credential helpers included even the following credential: ``` [credential "helperselector"] selected = manager-core ``` which gets introduced by Git for Windows and fails our assumption about what a credential helper is. The commit also removes a test that mirrors what `credential_helpers` does (otherwise, we would have to maintain the same regex at two places, the definition of `credential_helpers` and the test case). Fixes #45693 --- stdlib/LibGit2/src/gitcredential.jl | 2 +- stdlib/LibGit2/test/libgit2-tests.jl | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/stdlib/LibGit2/src/gitcredential.jl b/stdlib/LibGit2/src/gitcredential.jl index 1b97c29cd933e..acfde02578523 100644 --- a/stdlib/LibGit2/src/gitcredential.jl +++ b/stdlib/LibGit2/src/gitcredential.jl @@ -219,7 +219,7 @@ function credential_helpers(cfg::GitConfig, cred::GitCredential) helpers = GitCredentialHelper[] # https://git-scm.com/docs/gitcredentials#gitcredentials-helper - for entry in GitConfigIter(cfg, r"credential.*\.helper") + for entry in GitConfigIter(cfg, r"credential.*\.helper$") section, url, name, value = split_cfg_entry(entry) @assert name == "helper" diff --git a/stdlib/LibGit2/test/libgit2-tests.jl b/stdlib/LibGit2/test/libgit2-tests.jl index 4a86294dc87cd..4ace98a0b1ac8 100644 --- a/stdlib/LibGit2/test/libgit2-tests.jl +++ b/stdlib/LibGit2/test/libgit2-tests.jl @@ -1994,7 +1994,7 @@ mktempdir() do dir @test parse(GitCredentialHelper, "store") == GitCredentialHelper(`git credential-store`) end - @testset "empty helper" begin + @testset "credential_helpers" begin config_path = joinpath(dir, config_file) # Note: LibGit2.set! doesn't allow us to set duplicates or ordering @@ -2007,16 +2007,14 @@ mktempdir() do dir [credential] helper = !echo second """) + # Git for Windows uses this config (see issue #45693) + write(fp,""" + [credential "helperselector"] + selected = manager-core + """) end LibGit2.with(LibGit2.GitConfig(config_path, LibGit2.Consts.CONFIG_LEVEL_APP)) do cfg - iter = LibGit2.GitConfigIter(cfg, r"credential.*\.helper") - @test LibGit2.split_cfg_entry.(iter) == [ - ("credential", "", "helper", "!echo first"), - ("credential", "https://mygithost", "helper", ""), - ("credential", "", "helper", "!echo second"), - ] - expected = [ GitCredentialHelper(`echo first`), GitCredentialHelper(`echo second`),