Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with Git Credential Manager for Windows #30195

Merged
merged 1 commit into from
Nov 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion stdlib/LibGit2/src/gitcredential.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

const GIT_CRED_ATTRIBUTES = ("protocol", "host", "path", "username", "password", "url")

"""
GitCredential
Expand Down Expand Up @@ -111,16 +113,19 @@ function Base.read!(io::IO, cred::GitCredential)
else
value = readuntil(io, '\n')
end

if key == "url"
# Any components which are missing from the URL will be set to empty
# https://git-scm.com/docs/git-credential#git-credential-codeurlcode
Base.shred!(parse(GitCredential, value)) do urlcred
copy!(cred, urlcred)
end
else
elseif key in GIT_CRED_ATTRIBUTES
field = getproperty(cred, Symbol(key))
field !== nothing && Symbol(key) == :password && Base.shred!(field)
setproperty!(cred, Symbol(key), value)
elseif !all(isspace, key)
@warn "Unknown git credential attribute found: $(repr(key))"
end
end

Expand Down
39 changes: 39 additions & 0 deletions stdlib/LibGit2/test/libgit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,45 @@ end
Base.shred!(expected_cred)
end

@testset "extra newline" begin
# The "Git for Windows" installer will also install the "Git Credential Manager for
# Windows" (https://github.com/Microsoft/Git-Credential-Manager-for-Windows) (also
# known as "manager" in the .gitconfig files). This credential manager returns an
# additional newline when returning the results.
str = """
protocol=https
host=example.com
path=
username=bob
password=*****

"""
expected_cred = LibGit2.GitCredential("https", "example.com", "", "bob", "*****")

cred = read!(IOBuffer(str), LibGit2.GitCredential())
@test cred == expected_cred
@test sprint(write, cred) * "\n" == str
Base.shred!(cred)
Base.shred!(expected_cred)
end

@testset "unknown attribute" begin
str = """
protocol=https
host=example.com
attribute=value
username=bob
password=*****
"""
expected_cred = LibGit2.GitCredential("https", "example.com", nothing, "bob", "*****")
expected_log = (:warn, "Unknown git credential attribute found: \"attribute\"")

cred = @test_logs expected_log read!(IOBuffer(str), LibGit2.GitCredential())
@test cred == expected_cred
Base.shred!(cred)
Base.shred!(expected_cred)
end

@testset "use http path" begin
cred = LibGit2.GitCredential("https", "example.com", "dir/file", "alice", "*****")
expected = """
Expand Down