Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: CI

on:
pull_request:
branches:
- master
push:
branches:
- master
Expand Down Expand Up @@ -61,7 +59,15 @@ jobs:
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v2
- uses: julia-actions/julia-buildpkg@v1
- name: On Linux and Windows, ssh-keyscan github.com and store in known-hosts
shell: bash
run: |
mkdir -p ~/.ssh
ssh-keyscan github.com >> ~/.ssh/known_hosts
if: runner.os == 'Linux' || runner.os == 'Windows'
- uses: julia-actions/julia-runtest@v1
env:
CI_READONLY_DEPLOYKEY_FOR_CI_TESTSUITE_PRIVATEKEY: ${{ secrets.CI_READONLY_DEPLOYKEY_FOR_CI_TESTSUITE_PRIVATEKEY }}
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v5
with:
Expand Down
8 changes: 5 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
name = "Git"
uuid = "d7ba0133-e1db-5d97-8f8c-041e4b3a1eb2"
version = "1.4.0"
authors = ["Dilum Aluthge", "contributors"]
version = "1.3.1"

[deps]
Git_jll = "f8c6e375-362e-5223-8a59-34ff63f689eb"
JLLWrappers = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
OpenSSH_jll = "9bd350c2-7e96-507f-8002-3f2e150b4e1b"

[compat]
Git_jll = "2.44"
JLLWrappers = "1.1"
OpenSSH_jll = "9, 10"
julia = "1.6"

[extras]
JLLWrappers = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["JLLWrappers", "Test"]
test = ["Test"]
27 changes: 24 additions & 3 deletions src/git_function.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using OpenSSH_jll: OpenSSH_jll
using JLLWrappers: pathsep, LIBPATH_env

"""
git()

Expand All @@ -18,8 +21,8 @@ julia> run(git(["clone", "https://github.com/JuliaRegistries/General"]))
to bypass the parsing of the command string.
"""
function git(; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true)
@static if Sys.iswindows()
return Git_jll.git(; adjust_PATH, adjust_LIBPATH)::Cmd
git_cmd = @static if Sys.iswindows()
Git_jll.git(; adjust_PATH, adjust_LIBPATH)::Cmd
else
root = Git_jll.artifact_dir

Expand All @@ -45,8 +48,26 @@ function git(; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true)
end

original_cmd = Git_jll.git(; adjust_PATH, adjust_LIBPATH)::Cmd
return addenv(original_cmd, env_mapping...)::Cmd
addenv(original_cmd, env_mapping...)::Cmd
end

# Use OpenSSH from the JLL: <https://github.com/JuliaVersionControl/Git.jl/issues/51>.
if !Sys.iswindows() && OpenSSH_jll.is_available()
path = split(get(ENV, "PATH", ""), pathsep)
libpath = split(get(ENV, LIBPATH_env, ""), pathsep)

path = vcat(dirname(OpenSSH_jll.ssh_path), path)
libpath = vcat(OpenSSH_jll.LIBPATH_list, libpath)
path = vcat(dirname(Git_jll.git_path), path)
libpath = vcat(Git_jll.LIBPATH_list, libpath)

unique!(filter!(!isempty, path))
unique!(filter!(!isempty, libpath))

git_cmd = addenv(git_cmd, "PATH" => join(path, pathsep), LIBPATH_env => join(libpath, pathsep))
end

return git_cmd
end

function git(args::AbstractVector{<:AbstractString}; kwargs...)
Expand Down
36 changes: 36 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,39 @@ end
@test dir1_log == dir2_log
end; end
end

# https://github.com/JuliaVersionControl/Git.jl/issues/51
@testset "OpenSSH integration" begin
is_ci = parse(Bool, strip(get(ENV, "CI", "false")))
is_gha = parse(Bool, strip(get(ENV, "GITHUB_ACTIONS", "false")))
if is_ci && is_gha
@info "This is GitHub Actions CI, so running the OpenSSH test..."
mktempdir() do sshprivkeydir
privkey_filepath = joinpath(sshprivkeydir, "my_private_key")
open(privkey_filepath, "w") do io
ssh_privkey = ENV["CI_READONLY_DEPLOYKEY_FOR_CI_TESTSUITE_PRIVATEKEY"]
println(io, ssh_privkey)
end # open
# We need to chmod our private key to 600, or SSH will ignore it.
chmod(privkey_filepath, 0o600)

# ssh_verbose = "-vvv" # comment this line back out when you are finished debugging
ssh_verbose = "" # uncomment this line when you are finished debugging

withenv("GIT_SSH_COMMAND" => "ssh $(ssh_verbose) -i \"$(privkey_filepath)\"") do
withtempdir() do workdir
@test !isdir("Git.jl")
@test !isfile(joinpath("Git.jl", "Project.toml"))
# We use `run()` so that we can see the stdout and stderr in the CI logs:
proc = run(`$(git()) clone --depth=1 [email protected]:JuliaVersionControl/Git.jl.git`)
@test success(proc)
@test isdir("Git.jl")
@test isfile(joinpath("Git.jl", "Project.toml"))
end # withtempdir/workdir
end # withenv
end # withtempdir/sshprivkeydir
else
# Mark this test as skipped if we are not running in CI
@test_skip false
end # if
end # testset