Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add work around for SIP restrictions on macOS #45

Merged
merged 3 commits into from
Feb 17, 2023
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
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name = "Git"
uuid = "d7ba0133-e1db-5d97-8f8c-041e4b3a1eb2"
authors = ["Dilum Aluthge", "contributors"]
version = "1.2.1"
version = "1.3.0"

[deps]
Git_jll = "f8c6e375-362e-5223-8a59-34ff63f689eb"

[compat]
Git_jll = "2.31"
Git_jll = "2.36.1"
JLLWrappers = "1.1"
julia = "1.6"

Expand Down
7 changes: 7 additions & 0 deletions src/git_function.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ function git(; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true)
env_mapping["GIT_SSL_CAINFO"] = ssl_cert
env_mapping["GIT_TEMPLATE_DIR"] = share_git_core_templates

@static if Sys.isapple()
# This is needed to work around System Integrity Protection (SIP) restrictions
# on macOS. See <https://github.com/JuliaVersionControl/Git.jl/issues/40> for
# more details.
env_mapping["JLL_DYLD_FALLBACK_LIBRARY_PATH"] = Git_jll.LIBPATH[]
end

original_cmd = Git_jll.git(; adjust_PATH, adjust_LIBPATH)::Cmd
return addenv(original_cmd, env_mapping...)::Cmd
end
Expand Down
32 changes: 30 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ end
withtempdir() do tmp_dir
@test !isdir("Git.jl")
@test !isfile(joinpath("Git.jl", "Project.toml"))
run(`$(git()) clone https://github.com/JuliaVersionControl/Git.jl`)
run(`$(git()) clone --quiet https://github.com/JuliaVersionControl/Git.jl`)
@test isdir("Git.jl")
@test isfile(joinpath("Git.jl", "Project.toml"))
end

withtempdir() do tmp_dir
@test !isdir("Git.jl")
@test !isfile(joinpath("Git.jl", "Project.toml"))
run(git(["clone", "https://github.com/JuliaVersionControl/Git.jl"]))
run(git(["clone", "--quiet", "https://github.com/JuliaVersionControl/Git.jl"]))
@test isdir("Git.jl")
@test isfile(joinpath("Git.jl", "Project.toml"))
end
Expand All @@ -43,3 +43,31 @@ end
@test orig_cainfo == get_env("GIT_SSL_CAINFO")
@test orig_templatedir == get_env("GIT_TEMPLATE_DIR")
end

# This makes sure the work around for the SIP restrictions on macOS
# (<https://github.com/JuliaVersionControl/Git.jl/issues/40>) works correctly. While SIP is
# a macOS-specific issue, it's good to exercise this code path everywhere.
@testset "SIP workaround" begin
gitd(dir, cmd; stdout=Base.stdout, stderr=Base.stderr) =
success(pipeline(`$(git()) -C $(dir) -c "user.name=a" -c "user.email=b@c" $(cmd)`;
stdout, stderr))
branch = "dev"
mktempdir() do dir1; mktempdir() do dir2;
@test gitd(dir1, `init --bare --quiet --initial-branch $(branch)`)
@test gitd(dir2, `init --quiet --initial-branch $(branch)`)
open(joinpath(dir2, "README"); write=true) do io
println(io, "test")
end
@test gitd(dir2, `add --all`)
@test gitd(dir2, `commit --quiet -m test`)
@test gitd(dir2, `remote add origin file://$(dir1)`)
@test gitd(dir2, `push --quiet --set-upstream origin $(branch)`)
dir1_io, dir2_io = IOBuffer(), IOBuffer()
@test gitd(dir1, `log`; stdout=dir1_io)
@test gitd(dir2, `log`; stdout=dir2_io)
# Make sure the logs are the same for the two repositories
dir1_log, dir2_log = String.(take!.((dir1_io, dir2_io)))
@test !isempty(dir1_log) === !isempty(dir2_log) === true
@test dir1_log == dir2_log
end; end
end