Skip to content

Commit

Permalink
Don't override authentication callbacks in libgit2 clone
Browse files Browse the repository at this point in the history
Use the supported callbacks interface rather than trying to re-do
the low level interface. As reported in JuliaPackaging/BinaryBuilder.jl#1287,
we currently try to error when attempting to clone a repository
over ssh (either directly or via the insteadOf git setting),
because we accidentally override the base callback to provide
ssh credentials.

Fixes JuliaPackaging/BinaryBuilder.jl#1287
  • Loading branch information
Keno committed Sep 13, 2023
1 parent 29051e0 commit f4e3203
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
23 changes: 9 additions & 14 deletions src/Sources.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ struct GitTransferProgress
received_bytes::Csize_t
end

function transfer_progress(progress::Ptr{GitTransferProgress}, p::Any)
function transfer_progress(progress::Ptr{GitTransferProgress}, payloads::Dict)
p = payloads[:transfer_progress]
progress = unsafe_load(progress)
p.n = progress.total_objects
if progress.total_deltas != 0
Expand Down Expand Up @@ -193,25 +194,19 @@ function cached_git_clone(url::String;
if verbose
@info("Cloning git repository", url, repo_path)
end
callbacks = LibGit2.Callbacks()
p = Progress(0, 1, "Cloning: ")
if progressbar
# Clone with a progress bar
p = Progress(0, 1, "Cloning: ")
GC.@preserve p begin
callbacks = LibGit2.RemoteCallbacks(
transfer_progress=@cfunction(
callbacks[:transfer_progress] = (
@cfunction(
transfer_progress,
Cint,
(Ptr{GitTransferProgress}, Any)
),
payload = p
)
fetch_opts = LibGit2.FetchOptions(; callbacks)
clone_opts = LibGit2.CloneOptions(; fetch_opts, bare = Cint(true))
LibGit2.clone(url, repo_path, clone_opts)
end
else
LibGit2.clone(url, repo_path; isbare=true)
p
)
end
LibGit2.clone(url, repo_path; isbare=true, callbacks)
end
return repo_path
end
Expand Down
39 changes: 22 additions & 17 deletions test/dependencies.jl
Original file line number Diff line number Diff line change
Expand Up @@ -248,24 +248,29 @@ end
end

# Dependency as a local directory
with_temp_project() do dir
mktempdir() do pkgdir
prefix = Prefix(dir)
# Clone if necessary the remote repository and check out its
# working directory in a temporary space.
cache_dir = cached_git_clone("https://github.com/JuliaBinaryWrappers/HelloWorldC_jll.jl")
LibGit2.with(LibGit2.clone(cache_dir, pkgdir)) do repo
LibGit2.checkout!(repo, "c7f2e95d9c04e218931c14954ecd31ebde72cca5")
for remote_url in (
"https://github.com/JuliaBinaryWrappers/HelloWorldC_jll.jl",
"ssh://git@github.com/JuliaBinaryWrappers/HelloWorldC_jll.jl"
)
with_temp_project() do dir
mktempdir() do pkgdir
prefix = Prefix(dir)
# Clone if necessary the remote repository and check out its
# working directory in a temporary space.
cache_dir = cached_git_clone(remote_url)
LibGit2.with(LibGit2.clone(cache_dir, pkgdir)) do repo
LibGit2.checkout!(repo, "c7f2e95d9c04e218931c14954ecd31ebde72cca5")
end
dependencies = [
PackageSpec(
name="HelloWorldC_jll",
path=pkgdir,
),
]
platform = Platform("x86_64", "linux"; libc="glibc")
@test_logs setup_dependencies(prefix, dependencies, platform)
@test readdir(joinpath(destdir(dir, platform), "bin")) == ["hello_world"]
end
dependencies = [
PackageSpec(
name="HelloWorldC_jll",
path=pkgdir,
),
]
platform = Platform("x86_64", "linux"; libc="glibc")
@test_logs setup_dependencies(prefix, dependencies, platform)
@test readdir(joinpath(destdir(dir, platform), "bin")) == ["hello_world"]
end
end

Expand Down

0 comments on commit f4e3203

Please sign in to comment.