Skip to content

Commit

Permalink
Figure out default branch using git, fixes #1443, closes #1727.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Jan 14, 2022
1 parent 7beb208 commit f438cb7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

* ![Enhancement][badge-enhancement] MathJax 3 has been updated to `v3.2.0` (minor version bump). ([#1743][github-1743])
* ![Enhancement][badge-enhancement] Documenter now tries to detect the development branch using `git` with the old default (`master`) as fallback. If you use `main` as the development branch you shouldn't need to specify `devbranch = "main"` as an argument to deploydocs anymore. ([#1443][github-1443], [#1727][github-1727], [#1750][github-1750])

## Version `v0.27.10`

Expand Down Expand Up @@ -860,6 +861,7 @@
[github-1441]: https://github.com/JuliaDocs/Documenter.jl/pull/1441
[github-1448]: https://github.com/JuliaDocs/Documenter.jl/pull/1448
[github-1440]: https://github.com/JuliaDocs/Documenter.jl/pull/1440
[github-1443]: https://github.com/JuliaDocs/Documenter.jl/issues/1443
[github-1449]: https://github.com/JuliaDocs/Documenter.jl/issues/1449
[github-1452]: https://github.com/JuliaDocs/Documenter.jl/pull/1452
[github-1456]: https://github.com/JuliaDocs/Documenter.jl/pull/1456
Expand Down Expand Up @@ -946,7 +948,9 @@
[github-1706]: https://github.com/JuliaDocs/Documenter.jl/pull/1706
[github-1709]: https://github.com/JuliaDocs/Documenter.jl/pull/1709
[github-1716]: https://github.com/JuliaDocs/Documenter.jl/pull/1716
[github-1727]: https://github.com/JuliaDocs/Documenter.jl/pull/1727
[github-1743]: https://github.com/JuliaDocs/Documenter.jl/pull/1743
[github-1750]: https://github.com/JuliaDocs/Documenter.jl/pull/1750

[julia-38079]: https://github.com/JuliaLang/julia/issues/38079
[julia-39841]: https://github.com/JuliaLang/julia/pull/39841
Expand Down
18 changes: 15 additions & 3 deletions src/Documenter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ include("deployconfig.jl")
branch = "gh-pages",
deps = nothing | <Function>,
make = nothing | <Function>,
devbranch = "master",
devbranch = nothing,
devurl = "dev",
versions = ["stable" => "v^", "v#.#", devurl => devurl],
forcepush = false,
Expand Down Expand Up @@ -415,7 +415,8 @@ deps = Deps.pip("pygments", "mkdocs")
executed.
**`devbranch`** is the branch that "tracks" the in-development version of the generated
documentation. By default this value is set to `"master"`.
documentation. By default Documenter tries to figure this out using `git`. Can be set
explicitly as a string (typically `"master"` or `"main"`).
**`devurl`** the folder that in-development version of the docs will be deployed.
Defaults to `"dev"`.
Expand Down Expand Up @@ -491,14 +492,25 @@ function deploydocs(;
deps = nothing,
make = nothing,

devbranch = "master",
devbranch = nothing,
devurl = "dev",
versions = ["stable" => "v^", "v#.#", devurl => devurl],
forcepush::Bool = false,
deploy_config = auto_detect_deploy_system(),
push_preview::Bool = false,
)

# Try to figure out default branch (see #1443 and #1727)
if devbranch === nothing
str = try
read(pipeline(ignorestatus(setenv(`git remote show origin`; dir=root)); stderr=devnull), String)
catch
""
end
m = match(r"^\s*HEAD branch:\s*(.*)$"m, str)
devbranch = m === nothing ? "master" : String(m[1])
end

deploy_decision = deploy_folder(deploy_config;
branch=branch,
branch_previews=branch_previews,
Expand Down

0 comments on commit f438cb7

Please sign in to comment.