From dd0bf99db785a561b16432b6f30c56890dd05a91 Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Thu, 23 Nov 2017 09:32:37 -0600 Subject: [PATCH] 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. --- test/libgit2.jl | 101 +++++++++++++++++++++++------------------------- 1 file changed, 48 insertions(+), 53 deletions(-) diff --git a/test/libgit2.jl b/test/libgit2.jl index 1b9f1a1f1a05f..5300e7777c564 100644 --- a/test/libgit2.jl +++ b/test/libgit2.jl @@ -1700,31 +1700,29 @@ mktempdir() do dir # In order to use the "store" credential helper `git` needs to be installed and # on the path. if GIT_INSTALLED - config_path = joinpath(dir, config_file) credential_path = joinpath(dir, ".git-credentials") - - isfile(config_path) && rm(config_path) isfile(credential_path) && rm(credential_path) - LibGit2.with(LibGit2.GitConfig(config_path, LibGit2.Consts.CONFIG_LEVEL_APP)) do cfg - @test isempty(LibGit2.get(cfg, "credential.helper", "")) + # Requires `git` to be installed and available on the path. + helper = parse(LibGit2.GitCredentialHelper, "store") - helper = parse(LibGit2.GitCredentialHelper, "store") # Requires `git` - LibGit2.set!(cfg, "credential.helper", "store --file $credential_path") + # Set HOME to control where the .git-credentials file is written. + # Note: In Cygwin environments `git` will use HOME instead of USERPROFILE. + # Setting both environment variables ensures home was overridden. + withenv("HOME" => dir, "USERPROFILE" => dir) do + query = LibGit2.GitCredential("https", "mygithost") + filled = LibGit2.GitCredential("https", "mygithost", nothing, "bob", "s3cre7") - # Set HOME to control where .git-credentials file is written. - withenv(HOME => dir) do - query = LibGit2.GitCredential("https", "mygithost") - filled = LibGit2.GitCredential("https", "mygithost", nothing, "bob", "s3cre7") + @test !isfile(credential_path) - @test LibGit2.fill!(helper, deepcopy(query)) == query + @test LibGit2.fill!(helper, deepcopy(query)) == query - LibGit2.approve(helper, filled) - @test LibGit2.fill!(helper, deepcopy(query)) == filled + LibGit2.approve(helper, filled) + @test isfile(credential_path) + @test LibGit2.fill!(helper, deepcopy(query)) == filled - LibGit2.reject(helper, filled) - @test LibGit2.fill!(helper, deepcopy(query)) == query - end + LibGit2.reject(helper, filled) + @test LibGit2.fill!(helper, deepcopy(query)) == query end end end @@ -1733,53 +1731,50 @@ mktempdir() do dir # In order to use the "store" credential helper `git` needs to be installed and # on the path. if GIT_INSTALLED - config_path = joinpath(dir, config_file) credential_path = joinpath(dir, ".git-credentials") - - isfile(config_path) && rm(config_path) isfile(credential_path) && rm(credential_path) - LibGit2.with(LibGit2.GitConfig(config_path, LibGit2.Consts.CONFIG_LEVEL_APP)) do cfg - @test isempty(LibGit2.get(cfg, "credential.helper", "")) + # Requires `git` to be installed and available on the path. + helper = parse(LibGit2.GitCredentialHelper, "store") - helper = parse(LibGit2.GitCredentialHelper, "store") # Requires `git` - LibGit2.set!(cfg, "credential.helper", "store --file $credential_path") - LibGit2.set!(cfg, "credential.useHttpPath", "true") + # Set HOME to control where the .git-credentials file is written. + # Note: In Cygwin environments `git` will use HOME instead of USERPROFILE. + # Setting both environment variables ensures home was overridden. + withenv("HOME" => dir, "USERPROFILE" => dir) do + query = LibGit2.GitCredential("https", "mygithost") + query_a = LibGit2.GitCredential("https", "mygithost", "a") + query_b = LibGit2.GitCredential("https", "mygithost", "b") - # Set HOME to control where .git-credentials file is written. - withenv(HOME => dir) do - query = LibGit2.GitCredential("https", "mygithost") - query_a = LibGit2.GitCredential("https", "mygithost", "a") - query_b = LibGit2.GitCredential("https", "mygithost", "b") + filled_a = LibGit2.GitCredential("https", "mygithost", "a", "alice", "1234") + filled_b = LibGit2.GitCredential("https", "mygithost", "b", "bob", "s3cre7") - filled_a = LibGit2.GitCredential("https", "mygithost", "a", "alice", "1234") - filled_b = LibGit2.GitCredential("https", "mygithost", "b", "bob", "s3cre7") + function without_path(cred) + c = deepcopy(cred) + c.path = Nullable() + c + end - function without_path(cred) - c = deepcopy(cred) - c.path = Nullable() - c - end + @test !isfile(credential_path) - @test LibGit2.fill!(helper, deepcopy(query)) == query - @test LibGit2.fill!(helper, deepcopy(query_a)) == query_a - @test LibGit2.fill!(helper, deepcopy(query_b)) == query_b + @test LibGit2.fill!(helper, deepcopy(query)) == query + @test LibGit2.fill!(helper, deepcopy(query_a)) == query_a + @test LibGit2.fill!(helper, deepcopy(query_b)) == query_b - LibGit2.approve(helper, filled_a) - @test LibGit2.fill!(helper, deepcopy(query)) == without_path(filled_a) - @test LibGit2.fill!(helper, deepcopy(query_a)) == filled_a - @test LibGit2.fill!(helper, deepcopy(query_b)) == query_b + LibGit2.approve(helper, filled_a) + @test isfile(credential_path) + @test LibGit2.fill!(helper, deepcopy(query)) == without_path(filled_a) + @test LibGit2.fill!(helper, deepcopy(query_a)) == filled_a + @test LibGit2.fill!(helper, deepcopy(query_b)) == query_b - LibGit2.approve(helper, filled_b) - @test LibGit2.fill!(helper, deepcopy(query)) == without_path(filled_b) - @test LibGit2.fill!(helper, deepcopy(query_a)) == filled_a - @test LibGit2.fill!(helper, deepcopy(query_b)) == filled_b + LibGit2.approve(helper, filled_b) + @test LibGit2.fill!(helper, deepcopy(query)) == without_path(filled_b) + @test LibGit2.fill!(helper, deepcopy(query_a)) == filled_a + @test LibGit2.fill!(helper, deepcopy(query_b)) == filled_b - LibGit2.reject(helper, filled_b) - @test LibGit2.fill!(helper, deepcopy(query)) == without_path(filled_a) - @test LibGit2.fill!(helper, deepcopy(query_a)) == filled_a - @test LibGit2.fill!(helper, deepcopy(query_b)) == query_b - end + LibGit2.reject(helper, filled_b) + @test LibGit2.fill!(helper, deepcopy(query)) == without_path(filled_a) + @test LibGit2.fill!(helper, deepcopy(query_a)) == filled_a + @test LibGit2.fill!(helper, deepcopy(query_b)) == query_b end end end