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

handle git cli errors as pkgerrors #3538

Merged
merged 11 commits into from
Jul 17, 2023
14 changes: 12 additions & 2 deletions src/GitTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
40 changes: 26 additions & 14 deletions test/new.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down