Skip to content

Commit dd0bf99

Browse files
authored
Fix #24611 (#24694)
Within a Cygwin environment Julia tries to work like a native Windows program and uses Windows style paths and ENV["USERPROFILE"] for the user home directory. The credential helper tests which were failing use `git` found on the PATH. In Cygwin the `git` version expects POSIX style paths and uses ENV["HOME"] for the user home. In order to solve this problem I revised the tests to always set the HOME and USERPROFILE which ensures the user home is always overridden. Additionally, setting git configuration variables was unnecessary for these tests so it was removed.
1 parent 5caa891 commit dd0bf99

File tree

1 file changed

+48
-53
lines changed

1 file changed

+48
-53
lines changed

test/libgit2.jl

Lines changed: 48 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,31 +1700,29 @@ mktempdir() do dir
17001700
# In order to use the "store" credential helper `git` needs to be installed and
17011701
# on the path.
17021702
if GIT_INSTALLED
1703-
config_path = joinpath(dir, config_file)
17041703
credential_path = joinpath(dir, ".git-credentials")
1705-
1706-
isfile(config_path) && rm(config_path)
17071704
isfile(credential_path) && rm(credential_path)
17081705

1709-
LibGit2.with(LibGit2.GitConfig(config_path, LibGit2.Consts.CONFIG_LEVEL_APP)) do cfg
1710-
@test isempty(LibGit2.get(cfg, "credential.helper", ""))
1706+
# Requires `git` to be installed and available on the path.
1707+
helper = parse(LibGit2.GitCredentialHelper, "store")
17111708

1712-
helper = parse(LibGit2.GitCredentialHelper, "store") # Requires `git`
1713-
LibGit2.set!(cfg, "credential.helper", "store --file $credential_path")
1709+
# Set HOME to control where the .git-credentials file is written.
1710+
# Note: In Cygwin environments `git` will use HOME instead of USERPROFILE.
1711+
# Setting both environment variables ensures home was overridden.
1712+
withenv("HOME" => dir, "USERPROFILE" => dir) do
1713+
query = LibGit2.GitCredential("https", "mygithost")
1714+
filled = LibGit2.GitCredential("https", "mygithost", nothing, "bob", "s3cre7")
17141715

1715-
# Set HOME to control where .git-credentials file is written.
1716-
withenv(HOME => dir) do
1717-
query = LibGit2.GitCredential("https", "mygithost")
1718-
filled = LibGit2.GitCredential("https", "mygithost", nothing, "bob", "s3cre7")
1716+
@test !isfile(credential_path)
17191717

1720-
@test LibGit2.fill!(helper, deepcopy(query)) == query
1718+
@test LibGit2.fill!(helper, deepcopy(query)) == query
17211719

1722-
LibGit2.approve(helper, filled)
1723-
@test LibGit2.fill!(helper, deepcopy(query)) == filled
1720+
LibGit2.approve(helper, filled)
1721+
@test isfile(credential_path)
1722+
@test LibGit2.fill!(helper, deepcopy(query)) == filled
17241723

1725-
LibGit2.reject(helper, filled)
1726-
@test LibGit2.fill!(helper, deepcopy(query)) == query
1727-
end
1724+
LibGit2.reject(helper, filled)
1725+
@test LibGit2.fill!(helper, deepcopy(query)) == query
17281726
end
17291727
end
17301728
end
@@ -1733,53 +1731,50 @@ mktempdir() do dir
17331731
# In order to use the "store" credential helper `git` needs to be installed and
17341732
# on the path.
17351733
if GIT_INSTALLED
1736-
config_path = joinpath(dir, config_file)
17371734
credential_path = joinpath(dir, ".git-credentials")
1738-
1739-
isfile(config_path) && rm(config_path)
17401735
isfile(credential_path) && rm(credential_path)
17411736

1742-
LibGit2.with(LibGit2.GitConfig(config_path, LibGit2.Consts.CONFIG_LEVEL_APP)) do cfg
1743-
@test isempty(LibGit2.get(cfg, "credential.helper", ""))
1737+
# Requires `git` to be installed and available on the path.
1738+
helper = parse(LibGit2.GitCredentialHelper, "store")
17441739

1745-
helper = parse(LibGit2.GitCredentialHelper, "store") # Requires `git`
1746-
LibGit2.set!(cfg, "credential.helper", "store --file $credential_path")
1747-
LibGit2.set!(cfg, "credential.useHttpPath", "true")
1740+
# Set HOME to control where the .git-credentials file is written.
1741+
# Note: In Cygwin environments `git` will use HOME instead of USERPROFILE.
1742+
# Setting both environment variables ensures home was overridden.
1743+
withenv("HOME" => dir, "USERPROFILE" => dir) do
1744+
query = LibGit2.GitCredential("https", "mygithost")
1745+
query_a = LibGit2.GitCredential("https", "mygithost", "a")
1746+
query_b = LibGit2.GitCredential("https", "mygithost", "b")
17481747

1749-
# Set HOME to control where .git-credentials file is written.
1750-
withenv(HOME => dir) do
1751-
query = LibGit2.GitCredential("https", "mygithost")
1752-
query_a = LibGit2.GitCredential("https", "mygithost", "a")
1753-
query_b = LibGit2.GitCredential("https", "mygithost", "b")
1748+
filled_a = LibGit2.GitCredential("https", "mygithost", "a", "alice", "1234")
1749+
filled_b = LibGit2.GitCredential("https", "mygithost", "b", "bob", "s3cre7")
17541750

1755-
filled_a = LibGit2.GitCredential("https", "mygithost", "a", "alice", "1234")
1756-
filled_b = LibGit2.GitCredential("https", "mygithost", "b", "bob", "s3cre7")
1751+
function without_path(cred)
1752+
c = deepcopy(cred)
1753+
c.path = Nullable()
1754+
c
1755+
end
17571756

1758-
function without_path(cred)
1759-
c = deepcopy(cred)
1760-
c.path = Nullable()
1761-
c
1762-
end
1757+
@test !isfile(credential_path)
17631758

1764-
@test LibGit2.fill!(helper, deepcopy(query)) == query
1765-
@test LibGit2.fill!(helper, deepcopy(query_a)) == query_a
1766-
@test LibGit2.fill!(helper, deepcopy(query_b)) == query_b
1759+
@test LibGit2.fill!(helper, deepcopy(query)) == query
1760+
@test LibGit2.fill!(helper, deepcopy(query_a)) == query_a
1761+
@test LibGit2.fill!(helper, deepcopy(query_b)) == query_b
17671762

1768-
LibGit2.approve(helper, filled_a)
1769-
@test LibGit2.fill!(helper, deepcopy(query)) == without_path(filled_a)
1770-
@test LibGit2.fill!(helper, deepcopy(query_a)) == filled_a
1771-
@test LibGit2.fill!(helper, deepcopy(query_b)) == query_b
1763+
LibGit2.approve(helper, filled_a)
1764+
@test isfile(credential_path)
1765+
@test LibGit2.fill!(helper, deepcopy(query)) == without_path(filled_a)
1766+
@test LibGit2.fill!(helper, deepcopy(query_a)) == filled_a
1767+
@test LibGit2.fill!(helper, deepcopy(query_b)) == query_b
17721768

1773-
LibGit2.approve(helper, filled_b)
1774-
@test LibGit2.fill!(helper, deepcopy(query)) == without_path(filled_b)
1775-
@test LibGit2.fill!(helper, deepcopy(query_a)) == filled_a
1776-
@test LibGit2.fill!(helper, deepcopy(query_b)) == filled_b
1769+
LibGit2.approve(helper, filled_b)
1770+
@test LibGit2.fill!(helper, deepcopy(query)) == without_path(filled_b)
1771+
@test LibGit2.fill!(helper, deepcopy(query_a)) == filled_a
1772+
@test LibGit2.fill!(helper, deepcopy(query_b)) == filled_b
17771773

1778-
LibGit2.reject(helper, filled_b)
1779-
@test LibGit2.fill!(helper, deepcopy(query)) == without_path(filled_a)
1780-
@test LibGit2.fill!(helper, deepcopy(query_a)) == filled_a
1781-
@test LibGit2.fill!(helper, deepcopy(query_b)) == query_b
1782-
end
1774+
LibGit2.reject(helper, filled_b)
1775+
@test LibGit2.fill!(helper, deepcopy(query)) == without_path(filled_a)
1776+
@test LibGit2.fill!(helper, deepcopy(query_a)) == filled_a
1777+
@test LibGit2.fill!(helper, deepcopy(query_b)) == query_b
17831778
end
17841779
end
17851780
end

0 commit comments

Comments
 (0)