From 321d746010cbc93978fdb5899d3b4840f893e7fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mos=C3=A8=20Giordano?= Date: Thu, 16 Feb 2023 23:25:13 +0000 Subject: [PATCH 1/3] Add work around for SIP restrictions on macOS --- Project.toml | 4 ++-- src/git_function.jl | 7 +++++++ test/runtests.jl | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 3a45797..2861242 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/git_function.jl b/src/git_function.jl index 701f88d..867f697 100644 --- a/src/git_function.jl +++ b/src/git_function.jl @@ -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 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 diff --git a/test/runtests.jl b/test/runtests.jl index ad80b16..cc3bd9c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -43,3 +43,22 @@ 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 +# () 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) = run(`$(git()) -C $(dir) -c "user.name=a" -c "user.email=b@c" $(cmd)`) + branch = "dev" + mktempdir() do dir1; mktempdir() do dir2; + gitd(dir1, `init --bare --quiet --initial-branch $(branch)`) + gitd(dir2, `init --quiet --initial-branch $(branch)`) + open(joinpath(dir2, "README"); write=true) do io + println(io, "test") + end + gitd(dir2, `add --all`) + gitd(dir2, `commit --quiet -m test`) + gitd(dir2, `remote add origin file://$(dir1)`) + gitd(dir2, `push --quiet --set-upstream origin $(branch)`) + end; end +end From 00a57d81d0f825be248793036eeff8ffea76b656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mos=C3=A8=20Giordano?= Date: Thu, 16 Feb 2023 23:39:37 +0000 Subject: [PATCH 2/3] Silence other tests --- test/runtests.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index cc3bd9c..02bddab 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -22,7 +22,7 @@ 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 @@ -30,7 +30,7 @@ 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 From 3f4de1824181f0e77fa3420792879daeab5295a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mos=C3=A8=20Giordano?= Date: Thu, 16 Feb 2023 23:39:29 +0000 Subject: [PATCH 3/3] Actually test something --- test/runtests.jl | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 02bddab..5095d81 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -48,17 +48,26 @@ end # () 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) = run(`$(git()) -C $(dir) -c "user.name=a" -c "user.email=b@c" $(cmd)`) + 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; - gitd(dir1, `init --bare --quiet --initial-branch $(branch)`) - gitd(dir2, `init --quiet --initial-branch $(branch)`) + @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 - gitd(dir2, `add --all`) - gitd(dir2, `commit --quiet -m test`) - gitd(dir2, `remote add origin file://$(dir1)`) - gitd(dir2, `push --quiet --set-upstream origin $(branch)`) + @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