From 8dfe929cceedd84f967d6a5c968eaec40a530d20 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Mon, 5 Nov 2018 13:54:16 -0600 Subject: [PATCH] Make git stuff optional --- src/generate.jl | 82 +++++++++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 36 deletions(-) diff --git a/src/generate.jl b/src/generate.jl index ab46da4..42bef0c 100644 --- a/src/generate.jl +++ b/src/generate.jl @@ -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,35 +18,37 @@ function generate( # Create the directory with some boilerplate inside. Pkg.generate(pkg_dir) - # Initialize the repo. - repo = LibGit2.init(pkg_dir) - @info "Initialized git repo at $pkg_dir" + if git + # Initialize the repo. + repo = LibGit2.init(pkg_dir) + @info "Initialized git repo at $pkg_dir" - if gitconfig !== nothing - # Configure the repo. - repoconfig = GitConfig(repo) - for c in LibGit2.GitConfigIter(gitconfig) - LibGit2.set!(repoconfig, unsafe_string(c.name), unsafe_string(c.value)) + if gitconfig !== nothing + # Configure the repo. + repoconfig = GitConfig(repo) + for c in LibGit2.GitConfigIter(gitconfig) + LibGit2.set!(repoconfig, unsafe_string(c.name), unsafe_string(c.value)) + end end - end - # 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") + # Commit and set the remote. LibGit2.commit(repo, "Initial commit") - @info "Created empty gh-pages branch" - LibGit2.branch!(repo, "master") + 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") + @info "Created empty gh-pages branch" + LibGit2.branch!(repo, "master") + end end # Generate the files. @@ -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))...), ) - LibGit2.add!(repo, files...) - LibGit2.commit(repo, "Files generated by PkgTemplates") - @info "Committed $(length(files)) files/directories: $(join(files, ", "))" + 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, ", "))" + + + 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)) - if length(collect(LibGit2.GitBranchIter(repo))) > 1 - @info "Remember to push all created branches to your remote: git push --all" - end + @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