Skip to content

Commit

Permalink
LibGit2: correct regex for credential helpers
Browse files Browse the repository at this point in the history
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
  • Loading branch information
barucden committed Sep 6, 2022
1 parent f90da29 commit 0280c0a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion stdlib/LibGit2/src/gitcredential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
14 changes: 6 additions & 8 deletions stdlib/LibGit2/test/libgit2-tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`),
Expand Down

0 comments on commit 0280c0a

Please sign in to comment.