Skip to content

Commit

Permalink
handle git cli errors as pkgerrors (#3538)
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth authored Jul 17, 2023
1 parent f20beea commit b612bfd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
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

0 comments on commit b612bfd

Please sign in to comment.