Make git stuff optional

This commit is contained in:
Chris de Graaf 2018-11-05 13:54:16 -06:00
parent 56ec32c625
commit 8dfe929cce

View File

@ -2,11 +2,12 @@
generate(pkg::AbstractString, t::Template) -> 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(
pkg::AbstractString,
t::Template;
git::Bool=true,
gitconfig::Union{GitConfig, Nothing}=nothing,
)
pkg = splitjl(pkg)
@ -17,6 +18,7 @@ function generate(
# Create the directory with some boilerplate inside.
Pkg.generate(pkg_dir)
if git
# Initialize the repo.
repo = LibGit2.init(pkg_dir)
@info "Initialized git repo at $pkg_dir"
@ -47,6 +49,7 @@ function generate(
@info "Created empty gh-pages branch"
LibGit2.branch!(repo, "master")
end
end
# Generate the files.
files = vcat(
@ -54,21 +57,26 @@ function generate(
gen_tests(pkg_dir, t),
gen_require(pkg_dir, t),
gen_readme(pkg_dir, t),
gen_gitignore(pkg_dir, t),
gen_license(pkg_dir, t),
vcat(map(p -> gen_plugin(p, t, pkg), values(t.plugins))...),
)
if git
append!(files, gen_gitignore(pkg_dir, t))
LibGit2.add!(repo, files...)
LibGit2.commit(repo, "Files generated by PkgTemplates")
@info "Committed $(length(files)) files/directories: $(join(files, ", "))"
# Add the new package to the current environment.
Pkg.develop(PackageSpec(path=pkg_dir))
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.
Pkg.develop(PackageSpec(path=pkg_dir))
@info "New package is at $pkg_dir"
catch e
rm(pkg_dir; recursive=true)
rethrow(e)
@ -78,13 +86,14 @@ end
function generate(
t::Template,
pkg::AbstractString;
git::Bool=true,
gitconfig::Union{GitConfig, Nothing}=nothing,
)
generate(pkg, t; gitconfig=gitconfig)
generate(pkg, t; git=git, gitconfig=gitconfig)
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
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(
pkg::AbstractString;
fast::Bool=false,
git::Bool=true,
gitconfig::Union{GitConfig, Nothing}=nothing,
)
t = interactive_template(; fast=fast)
generate(pkg, t; gitconfig=gitconfig)
generate(pkg, t; git=git, gitconfig=gitconfig)
return t
end