Skip to content

Commit

Permalink
Small changes for GitLab (#971)
Browse files Browse the repository at this point in the history
* Extract SSH host from repo arg
* Create dir in `withfile` if needed
* Quote keyfile path in case of spaces
  • Loading branch information
JackDunnNZ authored and mortenpi committed Mar 3, 2019
1 parent 62d4f6f commit 1ee88b3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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
Expand Down
20 changes: 16 additions & 4 deletions src/Documenter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 1ee88b3

Please sign in to comment.