Allow setting custom default branch name (#192)
This commit is contained in:
parent
970554be7f
commit
52bac95d66
|
@ -1,7 +1,7 @@
|
|||
name = "PkgTemplates"
|
||||
uuid = "14b8a8f1-9102-5b29-a752-f990bacb7fe1"
|
||||
authors = ["Chris de Graaf", "Invenia Technical Computing Corporation"]
|
||||
version = "0.7.4"
|
||||
version = "0.7.5"
|
||||
|
||||
[deps]
|
||||
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
|
||||
|
|
|
@ -4,7 +4,7 @@ using Base: active_project, contractuser
|
|||
|
||||
using Dates: month, today, year
|
||||
using InteractiveUtils: subtypes
|
||||
using LibGit2: LibGit2, GitConfig, GitRemote, GitRepo
|
||||
using LibGit2: LibGit2, GitConfig, GitReference, GitRemote, GitRepo, delete_branch
|
||||
using Pkg: Pkg, TOML, PackageSpec
|
||||
using REPL.TerminalMenus: MultiSelectMenu, RadioMenu, request
|
||||
using UUIDs: uuid4
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
ignore=String[],
|
||||
name=nothing,
|
||||
email=nothing,
|
||||
branch=nothing,
|
||||
ssh=false,
|
||||
jl=true,
|
||||
manifest=false,
|
||||
|
@ -16,6 +17,7 @@ Creates a Git repository and a `.gitignore` file.
|
|||
See also: [`gitignore`](@ref).
|
||||
- `name::AbstractString`: Your real name, if you have not set `user.name` with Git.
|
||||
- `email::AbstractString`: Your email address, if you have not set `user.email` with Git.
|
||||
- `branch::AbstractString`: The desired name of the repository's default branch.
|
||||
- `ssh::Bool`: Whether or not to use SSH for the remote.
|
||||
If left unset, HTTPS is used.
|
||||
- `jl::Bool`: Whether or not to add a `.jl` suffix to the remote URL.
|
||||
|
@ -28,6 +30,7 @@ Creates a Git repository and a `.gitignore` file.
|
|||
ignore::Vector{String} = String[]
|
||||
name::Union{String, Nothing} = nothing
|
||||
email::Union{String, Nothing} = nothing
|
||||
branch::Union{String, Nothing} = nothing
|
||||
ssh::Bool = false
|
||||
jl::Bool = true
|
||||
manifest::Bool = false
|
||||
|
@ -73,9 +76,15 @@ function prehook(p::Git, t::Template, pkg_dir::AbstractString)
|
|||
else
|
||||
"https://$(t.host)/$(t.user)/$pkg$suffix"
|
||||
end
|
||||
default = LibGit2.branch(repo)
|
||||
branch = something(p.branch, default)
|
||||
if branch != default
|
||||
LibGit2.branch!(repo, branch)
|
||||
delete_branch(GitReference(repo, "refs/heads/$default"))
|
||||
end
|
||||
LibGit2.with(GitRemote(repo, "origin", url)) do remote
|
||||
LibGit2.add_fetch!(repo, remote, "refs/heads/master")
|
||||
LibGit2.add_push!(repo, remote, "refs/heads/master")
|
||||
LibGit2.add_fetch!(repo, remote, "refs/heads/$branch")
|
||||
LibGit2.add_push!(repo, remote, "refs/heads/$branch")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -57,6 +57,15 @@
|
|||
end
|
||||
end
|
||||
|
||||
@testset "With custom default branch" begin
|
||||
t = tpl(; plugins=[Git(; branch="main")])
|
||||
with_pkg(t) do pkg
|
||||
LibGit2.with(GitRepo(joinpath(t.dir, pkg))) do repo
|
||||
@test LibGit2.branch(repo) == "main"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@testset "Adds version to commit message" begin
|
||||
# We're careful to avoid a Pkg.update as it triggers Cassette#130.
|
||||
t = tpl(; plugins=[Git(), !Tests])
|
||||
|
|
|
@ -40,6 +40,7 @@ end
|
|||
ignore: String[]
|
||||
name: nothing
|
||||
email: nothing
|
||||
branch: nothing
|
||||
ssh: false
|
||||
jl: true
|
||||
manifest: false
|
||||
|
|
Loading…
Reference in New Issue