diff --git a/src/GitTools.jl b/src/GitTools.jl index a63dcde15a..d1d6551ebc 100644 --- a/src/GitTools.jl +++ b/src/GitTools.jl @@ -109,7 +109,12 @@ function clone(io::IO, url, source_path; header=nothing, credentials=nothing, kw end try if use_cli_git() - run(pipeline(`git clone --quiet $url $source_path`; stdout=devnull)) + cmd = `git clone --quiet $url $source_path` + try + run(pipeline(cmd; stdout=devnull)) + catch err + Pkg.Types.pkgerror("The command $(cmd) failed, error: $err") + end return LibGit2.GitRepo(source_path) else mkpath(source_path) @@ -161,7 +166,12 @@ function fetch(io::IO, repo::LibGit2.GitRepo, remoteurl=nothing; header=nothing, if use_cli_git() let remoteurl=remoteurl cd(LibGit2.path(repo)) do - run(pipeline(`git fetch -q $remoteurl $(only(refspecs))`; stdout=devnull)) + cmd = `git fetch -q $remoteurl $(only(refspecs))` + try + run(pipeline(cmd; stdout=devnull)) + catch err + Pkg.Types.pkgerror("The command $(cmd) failed, error: $err") + end end end else diff --git a/test/new.jl b/test/new.jl index dd5e5c731a..0062a8e98b 100644 --- a/test/new.jl +++ b/test/new.jl @@ -2687,22 +2687,34 @@ end # # Other # # Note: these tests should be run on clean depots -@testset "downloads" begin - for v in (nothing, "true") - withenv("JULIA_PKG_USE_CLI_GIT" => v) do - # libgit2 downloads - isolate() do - Pkg.add("Example"; use_git_for_all_downloads=true) - @test haskey(Pkg.dependencies(), exuuid) - @eval import $(Symbol(TEST_PKG.name)) - @test_throws SystemError open(pathof(eval(Symbol(TEST_PKG.name))), "w") do io end # check read-only - Pkg.rm(TEST_PKG.name) - end +for v in (nothing, "true") + withenv("JULIA_PKG_USE_CLI_GIT" => v, "GIT_TERMINAL_PROMPT" => 0) do + @testset "downloads with JULIA_PKG_USE_CLI_GIT = $v" begin isolate() do @testset "libgit2 downloads" begin - Pkg.add(TEST_PKG.name; use_git_for_all_downloads=true) - @test haskey(Pkg.dependencies(), TEST_PKG.uuid) - Pkg.rm(TEST_PKG.name) + @testset "via name" begin + Pkg.add(TEST_PKG.name; use_git_for_all_downloads=true) + @test haskey(Pkg.dependencies(), TEST_PKG.uuid) + @eval import $(Symbol(TEST_PKG.name)) + @test_throws SystemError open(pathof(eval(Symbol(TEST_PKG.name))), "w") do io end # check read-only + Pkg.rm(TEST_PKG.name) + end + if (Base.get_bool_env("JULIA_PKG_USE_CLI_GIT", false) && Sys.iswindows()) == false + # TODO: fix. on GH windows runners cli git will prompt for credentials here + @testset "via url" begin + Pkg.add(url="https://github.com/JuliaLang/Example.jl", use_git_for_all_downloads=true) + @test haskey(Pkg.dependencies(), TEST_PKG.uuid) + Pkg.rm(TEST_PKG.name) + end + end + end + if !Sys.iswindows() + # TODO: fix. on GH windows runners cli git will prompt for credentials here + @testset "libgit2 failures" begin + doesnotexist = "https://github.com/DoesNotExist/DoesNotExist.jl" + @test_throws Pkg.Types.PkgError Pkg.add(url=doesnotexist, use_git_for_all_downloads=true) + @test_throws Pkg.Types.PkgError Pkg.Registry.add(Pkg.RegistrySpec(url=doesnotexist)) + end end @testset "tarball downloads" begin Pkg.add("JSON"; use_only_tarballs_for_downloads=true)