Skip to content

Commit

Permalink
handle git cli errors as pkgerrors
Browse files Browse the repository at this point in the history
Co-Authored-By: Fredrik Ekre <[email protected]>
  • Loading branch information
IanButterworth and fredrikekre committed Jul 5, 2023
1 parent 2cd30ad commit ae84218
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 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
5 changes: 5 additions & 0 deletions test/new.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2704,6 +2704,11 @@ end
@test haskey(Pkg.dependencies(), TEST_PKG.uuid)
Pkg.rm(TEST_PKG.name)
end
@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
@testset "tarball downloads" begin
Pkg.add("JSON"; use_only_tarballs_for_downloads=true)
@test "JSON" in [pkg.name for (uuid, pkg) in Pkg.dependencies()]
Expand Down

0 comments on commit ae84218

Please sign in to comment.