Skip to content

Commit 64abc80

Browse files
authored
Add work around for SIP restrictions on macOS (#45)
* Add work around for SIP restrictions on macOS * Silence other tests * Actually test something
1 parent a7fd3e9 commit 64abc80

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
name = "Git"
22
uuid = "d7ba0133-e1db-5d97-8f8c-041e4b3a1eb2"
33
authors = ["Dilum Aluthge", "contributors"]
4-
version = "1.2.1"
4+
version = "1.3.0"
55

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

99
[compat]
10-
Git_jll = "2.31"
10+
Git_jll = "2.36.1"
1111
JLLWrappers = "1.1"
1212
julia = "1.6"
1313

src/git_function.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ function git(; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true)
3737
env_mapping["GIT_SSL_CAINFO"] = ssl_cert
3838
env_mapping["GIT_TEMPLATE_DIR"] = share_git_core_templates
3939

40+
@static if Sys.isapple()
41+
# This is needed to work around System Integrity Protection (SIP) restrictions
42+
# on macOS. See <https://github.com/JuliaVersionControl/Git.jl/issues/40> for
43+
# more details.
44+
env_mapping["JLL_DYLD_FALLBACK_LIBRARY_PATH"] = Git_jll.LIBPATH[]
45+
end
46+
4047
original_cmd = Git_jll.git(; adjust_PATH, adjust_LIBPATH)::Cmd
4148
return addenv(original_cmd, env_mapping...)::Cmd
4249
end

test/runtests.jl

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ end
2222
withtempdir() do tmp_dir
2323
@test !isdir("Git.jl")
2424
@test !isfile(joinpath("Git.jl", "Project.toml"))
25-
run(`$(git()) clone https://github.com/JuliaVersionControl/Git.jl`)
25+
run(`$(git()) clone --quiet https://github.com/JuliaVersionControl/Git.jl`)
2626
@test isdir("Git.jl")
2727
@test isfile(joinpath("Git.jl", "Project.toml"))
2828
end
2929

3030
withtempdir() do tmp_dir
3131
@test !isdir("Git.jl")
3232
@test !isfile(joinpath("Git.jl", "Project.toml"))
33-
run(git(["clone", "https://github.com/JuliaVersionControl/Git.jl"]))
33+
run(git(["clone", "--quiet", "https://github.com/JuliaVersionControl/Git.jl"]))
3434
@test isdir("Git.jl")
3535
@test isfile(joinpath("Git.jl", "Project.toml"))
3636
end
@@ -43,3 +43,31 @@ end
4343
@test orig_cainfo == get_env("GIT_SSL_CAINFO")
4444
@test orig_templatedir == get_env("GIT_TEMPLATE_DIR")
4545
end
46+
47+
# This makes sure the work around for the SIP restrictions on macOS
48+
# (<https://github.com/JuliaVersionControl/Git.jl/issues/40>) works correctly. While SIP is
49+
# a macOS-specific issue, it's good to exercise this code path everywhere.
50+
@testset "SIP workaround" begin
51+
gitd(dir, cmd; stdout=Base.stdout, stderr=Base.stderr) =
52+
success(pipeline(`$(git()) -C $(dir) -c "user.name=a" -c "user.email=b@c" $(cmd)`;
53+
stdout, stderr))
54+
branch = "dev"
55+
mktempdir() do dir1; mktempdir() do dir2;
56+
@test gitd(dir1, `init --bare --quiet --initial-branch $(branch)`)
57+
@test gitd(dir2, `init --quiet --initial-branch $(branch)`)
58+
open(joinpath(dir2, "README"); write=true) do io
59+
println(io, "test")
60+
end
61+
@test gitd(dir2, `add --all`)
62+
@test gitd(dir2, `commit --quiet -m test`)
63+
@test gitd(dir2, `remote add origin file://$(dir1)`)
64+
@test gitd(dir2, `push --quiet --set-upstream origin $(branch)`)
65+
dir1_io, dir2_io = IOBuffer(), IOBuffer()
66+
@test gitd(dir1, `log`; stdout=dir1_io)
67+
@test gitd(dir2, `log`; stdout=dir2_io)
68+
# Make sure the logs are the same for the two repositories
69+
dir1_log, dir2_log = String.(take!.((dir1_io, dir2_io)))
70+
@test !isempty(dir1_log) === !isempty(dir2_log) === true
71+
@test dir1_log == dir2_log
72+
end; end
73+
end

0 commit comments

Comments
 (0)