From 334102611ddc95d736b209cc9f6f441e372eb4ad Mon Sep 17 00:00:00 2001 From: Morten Piibeleht Date: Mon, 27 Nov 2023 12:19:58 +1300 Subject: [PATCH] Use Git.jl for `git` operations (#2348) --- CHANGELOG.md | 2 ++ Project.toml | 8 +++++--- src/Documenter.jl | 1 + src/utilities/utilities.jl | 26 +++++++++++++++++--------- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df8ef50e89..f22a4efc6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Documenter prints a more informative warning now if there is unexpected Julia interpolation in the Markdown (e.g. from errant `$` signs). ([#2288], [#2327]) * Documenter now warns when it encounters invalid keys in the various key-value at-blocks. ([#2306], [#2324]) * File sizes are now expressed in more human-readable format. ([#2272], [#2344]) +* Documenter now uses [Git.jl](https://github.com/JuliaVersionControl/Git.jl) (as opposed to the system's `git` binary) for Git operations. ([#2348]) ### Fixed @@ -1750,6 +1751,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#2329]: https://github.com/JuliaDocs/Documenter.jl/issues/2329 [#2330]: https://github.com/JuliaDocs/Documenter.jl/issues/2330 [#2344]: https://github.com/JuliaDocs/Documenter.jl/issues/2344 +[#2348]: https://github.com/JuliaDocs/Documenter.jl/issues/2348 [JuliaLang/julia#29344]: https://github.com/JuliaLang/julia/issues/29344 [JuliaLang/julia#36953]: https://github.com/JuliaLang/julia/issues/36953 [JuliaLang/julia#38054]: https://github.com/JuliaLang/julia/issues/38054 diff --git a/Project.toml b/Project.toml index 7bd3eec7d4..cf9fb128c4 100644 --- a/Project.toml +++ b/Project.toml @@ -9,6 +9,7 @@ Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6" +Git = "d7ba0133-e1db-5d97-8f8c-041e4b3a1eb2" IOCapture = "b5f81e59-6552-4d32-b1f0-c071b021bf89" InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" @@ -31,6 +32,7 @@ Base64 = "1.6" Dates = "1.6" DocStringExtensions = "0.4, 0.5, 0.6, 0.7, 0.8, 0.9" Downloads = "1.4" +Git = "1" IOCapture = "0.2" InteractiveUtils = "1.6" JSON = "0.19, 0.20, 0.21" @@ -40,13 +42,13 @@ Markdown = "1.6" MarkdownAST = "0.1.1" Pkg = "1.6" PrecompileTools = "1" -RegistryInstances = "0.1" -Random = "1.6" REPL = "1.6" +Random = "1.6" +RegistryInstances = "0.1" SHA = "0.7, 1.6" Test = "1.6" -Unicode = "1.6" UUIDs = "1.6" +Unicode = "1.6" julia = "1.6" [extras] diff --git a/src/Documenter.jl b/src/Documenter.jl index eab6f77716..3c9e066714 100644 --- a/src/Documenter.jl +++ b/src/Documenter.jl @@ -22,6 +22,7 @@ import REPL import Unicode import Pkg import RegistryInstances +import Git # Additional imported names using Test: @testset, @test using DocStringExtensions diff --git a/src/utilities/utilities.jl b/src/utilities/utilities.jl index 09a2a39436..6e393fe1bc 100644 --- a/src/utilities/utilities.jl +++ b/src/utilities/utilities.jl @@ -758,16 +758,24 @@ dropheaders(v::Vector) = map(dropheaders, v) dropheaders(other) = other function git(; nothrow = false, kwargs...) - system_git_path = Sys.which("git") - if system_git_path === nothing - return nothrow ? nothing : error("Unable to find `git`") - end - # According to the Git man page, the default GIT_TEMPLATE_DIR is at /usr/share/git-core/templates - # We need to set this to something so that Git wouldn't pick up the user - # templates (e.g. from init.templateDir config). - cmd = addenv(`$(system_git_path)`, "GIT_TEMPLATE_DIR" => "/usr/share/git-core/templates") # DOCUMENTER_KEY etc are never needed for git operations - cmd = addenv(cmd, NO_KEY_ENV) + cmd = addenv(Git.git(), NO_KEY_ENV) + if Sys.iswindows() + cmd = addenv(cmd, + # For deploydocs() in particular, we need to use symlinks, but it looks like those + # need to be explicitly force-enabled on Windows. So we make sure that we configure + # core.symlinks=true via environment variables on that platform. + "GIT_CONFIG_COUNT" => "1", + "GIT_CONFIG_KEY_0" => "core.symlinks", + "GIT_CONFIG_VALUE_0" => "true", + # Previously we used to set GIT_TEMPLATE_DIR=/usr/share/git-core/templates on all platforms. + # This was so that we wouldn't pick up the user's Git configuration. Git.jl, however, points + # the GIT_TEMPLATE_DIR to the artifact directory, and so we're mostly fine without setting + # now.. _except_ on Windows, where it doesn't set it. So we still set the environment variable + # on Windows, just in case. + "GIT_TEMPLATE_DIR" => "/usr/share/git-core/templates", + ) + end return cmd end