Make git stuff optional
This commit is contained in:
parent
56ec32c625
commit
8dfe929cce
@ -2,11 +2,12 @@
|
|||||||
generate(pkg::AbstractString, t::Template) -> Nothing
|
generate(pkg::AbstractString, t::Template) -> Nothing
|
||||||
generate(t::Template, pkg::AbstractString) -> Nothing
|
generate(t::Template, pkg::AbstractString) -> Nothing
|
||||||
|
|
||||||
Generate a package named `pkg` from `t`.
|
Generate a package named `pkg` from `t`. If `git` is `false`, no Git repository is created.
|
||||||
"""
|
"""
|
||||||
function generate(
|
function generate(
|
||||||
pkg::AbstractString,
|
pkg::AbstractString,
|
||||||
t::Template;
|
t::Template;
|
||||||
|
git::Bool=true,
|
||||||
gitconfig::Union{GitConfig, Nothing}=nothing,
|
gitconfig::Union{GitConfig, Nothing}=nothing,
|
||||||
)
|
)
|
||||||
pkg = splitjl(pkg)
|
pkg = splitjl(pkg)
|
||||||
@ -17,35 +18,37 @@ function generate(
|
|||||||
# Create the directory with some boilerplate inside.
|
# Create the directory with some boilerplate inside.
|
||||||
Pkg.generate(pkg_dir)
|
Pkg.generate(pkg_dir)
|
||||||
|
|
||||||
# Initialize the repo.
|
if git
|
||||||
repo = LibGit2.init(pkg_dir)
|
# Initialize the repo.
|
||||||
@info "Initialized git repo at $pkg_dir"
|
repo = LibGit2.init(pkg_dir)
|
||||||
|
@info "Initialized git repo at $pkg_dir"
|
||||||
|
|
||||||
if gitconfig !== nothing
|
if gitconfig !== nothing
|
||||||
# Configure the repo.
|
# Configure the repo.
|
||||||
repoconfig = GitConfig(repo)
|
repoconfig = GitConfig(repo)
|
||||||
for c in LibGit2.GitConfigIter(gitconfig)
|
for c in LibGit2.GitConfigIter(gitconfig)
|
||||||
LibGit2.set!(repoconfig, unsafe_string(c.name), unsafe_string(c.value))
|
LibGit2.set!(repoconfig, unsafe_string(c.name), unsafe_string(c.value))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# Commit and set the remote.
|
# Commit and set the remote.
|
||||||
LibGit2.commit(repo, "Initial commit")
|
|
||||||
rmt = if t.ssh
|
|
||||||
"git@$(t.host):$(t.user)/$pkg.jl.git"
|
|
||||||
else
|
|
||||||
"https://$(t.host)/$(t.user)/$pkg.jl"
|
|
||||||
end
|
|
||||||
# We need to set the remote in a strange way, see #8.
|
|
||||||
close(LibGit2.GitRemote(repo, "origin", rmt))
|
|
||||||
@info "Set remote origin to $rmt"
|
|
||||||
|
|
||||||
# Create the gh-pages branch if necessary.
|
|
||||||
if haskey(t.plugins, GitHubPages)
|
|
||||||
LibGit2.branch!(repo, "gh-pages")
|
|
||||||
LibGit2.commit(repo, "Initial commit")
|
LibGit2.commit(repo, "Initial commit")
|
||||||
@info "Created empty gh-pages branch"
|
rmt = if t.ssh
|
||||||
LibGit2.branch!(repo, "master")
|
"git@$(t.host):$(t.user)/$pkg.jl.git"
|
||||||
|
else
|
||||||
|
"https://$(t.host)/$(t.user)/$pkg.jl"
|
||||||
|
end
|
||||||
|
# We need to set the remote in a strange way, see #8.
|
||||||
|
close(LibGit2.GitRemote(repo, "origin", rmt))
|
||||||
|
@info "Set remote origin to $rmt"
|
||||||
|
|
||||||
|
# Create the gh-pages branch if necessary.
|
||||||
|
if haskey(t.plugins, GitHubPages)
|
||||||
|
LibGit2.branch!(repo, "gh-pages")
|
||||||
|
LibGit2.commit(repo, "Initial commit")
|
||||||
|
@info "Created empty gh-pages branch"
|
||||||
|
LibGit2.branch!(repo, "master")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Generate the files.
|
# Generate the files.
|
||||||
@ -54,21 +57,26 @@ function generate(
|
|||||||
gen_tests(pkg_dir, t),
|
gen_tests(pkg_dir, t),
|
||||||
gen_require(pkg_dir, t),
|
gen_require(pkg_dir, t),
|
||||||
gen_readme(pkg_dir, t),
|
gen_readme(pkg_dir, t),
|
||||||
gen_gitignore(pkg_dir, t),
|
|
||||||
gen_license(pkg_dir, t),
|
gen_license(pkg_dir, t),
|
||||||
vcat(map(p -> gen_plugin(p, t, pkg), values(t.plugins))...),
|
vcat(map(p -> gen_plugin(p, t, pkg), values(t.plugins))...),
|
||||||
)
|
)
|
||||||
|
|
||||||
LibGit2.add!(repo, files...)
|
if git
|
||||||
LibGit2.commit(repo, "Files generated by PkgTemplates")
|
append!(files, gen_gitignore(pkg_dir, t))
|
||||||
@info "Committed $(length(files)) files/directories: $(join(files, ", "))"
|
LibGit2.add!(repo, files...)
|
||||||
|
LibGit2.commit(repo, "Files generated by PkgTemplates")
|
||||||
|
@info "Committed $(length(files)) files/directories: $(join(files, ", "))"
|
||||||
|
|
||||||
|
|
||||||
|
if length(collect(LibGit2.GitBranchIter(repo))) > 1
|
||||||
|
@info "Remember to push all created branches to your remote: git push --all"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Add the new package to the current environment.
|
# Add the new package to the current environment.
|
||||||
Pkg.develop(PackageSpec(path=pkg_dir))
|
Pkg.develop(PackageSpec(path=pkg_dir))
|
||||||
|
|
||||||
if length(collect(LibGit2.GitBranchIter(repo))) > 1
|
@info "New package is at $pkg_dir"
|
||||||
@info "Remember to push all created branches to your remote: git push --all"
|
|
||||||
end
|
|
||||||
catch e
|
catch e
|
||||||
rm(pkg_dir; recursive=true)
|
rm(pkg_dir; recursive=true)
|
||||||
rethrow(e)
|
rethrow(e)
|
||||||
@ -78,13 +86,14 @@ end
|
|||||||
function generate(
|
function generate(
|
||||||
t::Template,
|
t::Template,
|
||||||
pkg::AbstractString;
|
pkg::AbstractString;
|
||||||
|
git::Bool=true,
|
||||||
gitconfig::Union{GitConfig, Nothing}=nothing,
|
gitconfig::Union{GitConfig, Nothing}=nothing,
|
||||||
)
|
)
|
||||||
generate(pkg, t; gitconfig=gitconfig)
|
generate(pkg, t; git=git, gitconfig=gitconfig)
|
||||||
end
|
end
|
||||||
|
|
||||||
"""
|
"""
|
||||||
generate_interactive(pkg::AbstractString; fast::Bool=false) -> Template
|
generate_interactive(pkg::AbstractString; fast::Bool=false, git::Bool=true) -> Template
|
||||||
|
|
||||||
Interactively create a template, and then generate a package with it. Arguments and
|
Interactively create a template, and then generate a package with it. Arguments and
|
||||||
keywords are used in the same way as in [`generate`](@ref) and
|
keywords are used in the same way as in [`generate`](@ref) and
|
||||||
@ -93,10 +102,11 @@ keywords are used in the same way as in [`generate`](@ref) and
|
|||||||
function generate_interactive(
|
function generate_interactive(
|
||||||
pkg::AbstractString;
|
pkg::AbstractString;
|
||||||
fast::Bool=false,
|
fast::Bool=false,
|
||||||
|
git::Bool=true,
|
||||||
gitconfig::Union{GitConfig, Nothing}=nothing,
|
gitconfig::Union{GitConfig, Nothing}=nothing,
|
||||||
)
|
)
|
||||||
t = interactive_template(; fast=fast)
|
t = interactive_template(; fast=fast)
|
||||||
generate(pkg, t; gitconfig=gitconfig)
|
generate(pkg, t; git=git, gitconfig=gitconfig)
|
||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user