From 1ee88b33169719e1dc0d1b6de545a72b66e9c413 Mon Sep 17 00:00:00 2001 From: Jack Dunn Date: Sat, 2 Mar 2019 20:06:50 -0500 Subject: [PATCH] Small changes for GitLab (#971) * Extract SSH host from repo arg * Create dir in `withfile` if needed * Quote keyfile path in case of spaces --- CHANGELOG.md | 3 +++ src/Documenter.jl | 20 ++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 355e378e29..a645f49f4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,8 @@ blocks are now interpreted to be relative `pwd`, which is set to the output directory of the resulting file. ([#941][github-941]) +* ![Bugfix][badge-bugfix] `deploydocs` and `git_push` now support non-github repos correctly and work when the `.ssh` directory does not already exist or the working directory contains spaces. ([#971][github-971]) + ## Version `v0.21.5` * ![Bugfix][badge-bugfix] Deprecation warnings for `format` now get printed correctly when multiple formats are passed as a `Vector`. ([#967][github-967]) @@ -264,6 +266,7 @@ [github-959]: https://github.com/JuliaDocs/Documenter.jl/pull/959 [github-960]: https://github.com/JuliaDocs/Documenter.jl/pull/960 [github-967]: https://github.com/JuliaDocs/Documenter.jl/pull/967 +[github-971]: https://github.com/JuliaDocs/Documenter.jl/pull/971 [documenterlatex]: https://github.com/JuliaDocs/DocumenterLaTeX.jl [documentermarkdown]: https://github.com/JuliaDocs/DocumenterMarkdown.jl diff --git a/src/Documenter.jl b/src/Documenter.jl index 7f48750761..d194c16d77 100644 --- a/src/Documenter.jl +++ b/src/Documenter.jl @@ -606,8 +606,11 @@ function git_push( target_dir = abspath(target) + # Extract host from repo as everything up to first ':' or '/' character + host = match(r"(.*?)[:\/]", repo)[1] + # The upstream URL to which we push new content and the ssh decryption commands. - upstream = "git@$(replace(repo, "github.com/" => "github.com:"))" + upstream = "git@$(replace(repo, "$host/" => "$host:"))" keyfile = abspath(joinpath(root, ".documenter")) try @@ -626,10 +629,10 @@ function git_push( # Use a custom SSH config file to avoid overwriting the default user config. withfile(joinpath(homedir(), ".ssh", "config"), """ - Host github.com + Host $host StrictHostKeyChecking no - HostName github.com - IdentityFile $keyfile + HostName $host + IdentityFile "$keyfile" BatchMode yes """ ) do @@ -747,6 +750,10 @@ function gitrm_copy(src, dst) end function withfile(func, file::AbstractString, contents::AbstractString) + dir = dirname(file) + hasdir = isdir(dir) + hasdir || mkpath(dir) + hasfile = isfile(file) original = hasfile ? read(file, String) : "" open(file, "w") do stream @@ -763,6 +770,11 @@ function withfile(func, file::AbstractString, contents::AbstractString) else rm(file) end + + if !hasdir + # dir should be empty now as the only file inside was deleted + rm(dir, recursive=true) + end end end