Skip to content

Commit 18e421f

Browse files
authored
Don't override authentication callbacks in libgit2 clone (#319)
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
1 parent 21a1c77 commit 18e421f

File tree

4 files changed

+48
-31
lines changed

4 files changed

+48
-31
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ jobs:
6868
run: julia --project=. --color=yes -e "using BinaryBuilderBase; BinaryBuilderBase.versioninfo()"
6969
- name: Run tests
7070
run: |
71+
eval `ssh-agent`
72+
chmod 0600 test/id_ecdsa_deploy_helloworld_c_jll_read_only
73+
mkdir -p ~/.ssh
74+
touch ~/.ssh/known_hosts
75+
ssh-keyscan github.com >> ~/.ssh/known_hosts
76+
ssh-add test/id_ecdsa_deploy_helloworld_c_jll_read_only
7177
julia --check-bounds=yes --color=yes --depwarn=yes --inline=yes --project=@. -e 'using Pkg; Pkg.instantiate(); Pkg.test(coverage=true)'
7278
- uses: julia-actions/[email protected]
7379
continue-on-error: true

src/Sources.jl

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ struct GitTransferProgress
186186
received_bytes::Csize_t
187187
end
188188

189-
function transfer_progress(progress::Ptr{GitTransferProgress}, p::Any)
189+
function transfer_progress(progress::Ptr{GitTransferProgress}, payloads::Dict)
190+
p = payloads[:transfer_progress]
190191
progress = unsafe_load(progress)
191192
p.n = progress.total_objects
192193
if progress.total_deltas != 0
@@ -225,25 +226,19 @@ function cached_git_clone(url::String;
225226
if verbose
226227
@info("Cloning git repository", url, repo_path)
227228
end
229+
callbacks = LibGit2.Callbacks()
230+
p = Progress(0, dt=1, desc="Cloning: ")
228231
if progressbar
229-
# Clone with a progress bar
230-
p = Progress(0, 1, "Cloning: ")
231-
GC.@preserve p begin
232-
callbacks = LibGit2.RemoteCallbacks(
233-
transfer_progress=@cfunction(
232+
callbacks[:transfer_progress] = (
233+
@cfunction(
234234
transfer_progress,
235235
Cint,
236236
(Ptr{GitTransferProgress}, Any)
237237
),
238-
payload = p
239-
)
240-
fetch_opts = LibGit2.FetchOptions(; callbacks)
241-
clone_opts = LibGit2.CloneOptions(; fetch_opts, bare = Cint(true))
242-
LibGit2.clone(url, repo_path, clone_opts)
243-
end
244-
else
245-
LibGit2.clone(url, repo_path; isbare=true)
238+
p
239+
)
246240
end
241+
LibGit2.clone(url, repo_path; isbare=true, callbacks)
247242
end
248243
return repo_path
249244
end

test/dependencies.jl

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -275,24 +275,31 @@ end
275275
end
276276

277277
# Dependency as a local directory
278-
with_temp_project() do dir
279-
mktempdir() do pkgdir
280-
prefix = Prefix(dir)
281-
# Clone if necessary the remote repository and check out its
282-
# working directory in a temporary space.
283-
cache_dir = cached_git_clone("https://github.com/JuliaBinaryWrappers/HelloWorldC_jll.jl")
284-
LibGit2.with(LibGit2.clone(cache_dir, pkgdir)) do repo
285-
LibGit2.checkout!(repo, "c7f2e95d9c04e218931c14954ecd31ebde72cca5")
278+
for remote_url in (
279+
"https://github.com/JuliaBinaryWrappers/HelloWorldC_jll.jl",
280+
"ssh://[email protected]/JuliaBinaryWrappers/HelloWorldC_jll.jl"
281+
)
282+
for progressbar in (true, false)
283+
with_temp_project() do dir
284+
mktempdir() do pkgdir
285+
prefix = Prefix(dir)
286+
# Clone if necessary the remote repository and check out its
287+
# working directory in a temporary space.
288+
cache_dir = cached_git_clone(remote_url; progressbar)
289+
LibGit2.with(LibGit2.clone(cache_dir, pkgdir)) do repo
290+
LibGit2.checkout!(repo, "c7f2e95d9c04e218931c14954ecd31ebde72cca5")
291+
end
292+
dependencies = [
293+
PackageSpec(
294+
name="HelloWorldC_jll",
295+
path=pkgdir,
296+
),
297+
]
298+
platform = Platform("x86_64", "linux"; libc="glibc")
299+
@test_logs setup_dependencies(prefix, dependencies, platform)
300+
@test readdir(joinpath(destdir(dir, platform), "bin")) == ["hello_world"]
301+
end
286302
end
287-
dependencies = [
288-
PackageSpec(
289-
name="HelloWorldC_jll",
290-
path=pkgdir,
291-
),
292-
]
293-
platform = Platform("x86_64", "linux"; libc="glibc")
294-
@test_logs setup_dependencies(prefix, dependencies, platform)
295-
@test readdir(joinpath(destdir(dir, platform), "bin")) == ["hello_world"]
296303
end
297304
end
298305

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-----BEGIN OPENSSH PRIVATE KEY-----
2+
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAaAAAABNlY2RzYS
3+
1zaGEyLW5pc3RwMjU2AAAACG5pc3RwMjU2AAAAQQQg84ce7J+he7ByXanYD0nGVpw2b7h2
4+
1PJLi1MjyDTiT2iSZyLe9GMB1O5wx8/XS3NjAPghz5Y1vxfcGlw64DlbAAAAwIVGhjKFRo
5+
YyAAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBCDzhx7sn6F7sHJd
6+
qdgPScZWnDZvuHbU8kuLUyPINOJPaJJnIt70YwHU7nDHz9dLc2MA+CHPljW/F9waXDrgOV
7+
sAAAAhAJ6u+41H8CUK5xnn1NiP3KODYU8iS3o0b3/+2emYw/03AAAAImtlbm9AS2Vub3Mt
8+
TWFjQm9vay1Qcm8tMi5mcml0ei5ib3gBAgMEBQ==
9+
-----END OPENSSH PRIVATE KEY-----

0 commit comments

Comments
 (0)