Merge pull request #39 from invenia/cdg/manifest
Don't commit manifest by default
This commit is contained in:
commit
2822ae4619
@ -145,7 +145,7 @@ function gen_tests(pkg_dir::AbstractString, t::Template)
|
||||
"""
|
||||
|
||||
gen_file(joinpath(pkg_dir, "test", "runtests.jl"), text)
|
||||
return ["Manifest.toml", "test/"]
|
||||
return ["test/"]
|
||||
end
|
||||
|
||||
"""
|
||||
@ -217,6 +217,7 @@ Returns an array of generated file/directory names.
|
||||
function gen_gitignore(pkg_dir::AbstractString, t::Template)
|
||||
pkg = basename(pkg_dir)
|
||||
seen = [".DS_Store"]
|
||||
t.manifest || push!(seen, "Manifest.toml")
|
||||
patterns = vcat(map(p -> p.gitignore, values(t.plugins))...)
|
||||
for pattern in patterns
|
||||
if !in(pattern, seen)
|
||||
@ -226,7 +227,9 @@ function gen_gitignore(pkg_dir::AbstractString, t::Template)
|
||||
text = join(seen, "\n")
|
||||
|
||||
gen_file(joinpath(pkg_dir, ".gitignore"), text)
|
||||
return [".gitignore"]
|
||||
files = [".gitignore"]
|
||||
t.manifest && push!(files, "Manifest.toml")
|
||||
return files
|
||||
end
|
||||
|
||||
"""
|
||||
|
@ -23,6 +23,7 @@ create a template, you can use [`interactive_template`](@ref) instead.
|
||||
package will go. Relative paths are converted to absolute ones at template creation time.
|
||||
* `julia_version::VersionNumber=$VERSION`: Minimum allowed Julia version.
|
||||
* `ssh::Bool=false`: Whether or not to use SSH for the remote.
|
||||
* `manifest::Bool=false`: Whether or not to commit the `Manifest.toml`.
|
||||
* `plugins::Vector{<:Plugin}=Plugin[]`: A list of `Plugin`s that the package will include.
|
||||
"""
|
||||
@auto_hash_equals struct Template
|
||||
@ -33,6 +34,7 @@ create a template, you can use [`interactive_template`](@ref) instead.
|
||||
dir::AbstractString
|
||||
julia_version::VersionNumber
|
||||
ssh::Bool
|
||||
manifest::Bool
|
||||
plugins::Dict{DataType, Plugin}
|
||||
|
||||
function Template(;
|
||||
@ -43,6 +45,7 @@ create a template, you can use [`interactive_template`](@ref) instead.
|
||||
dir::AbstractString=Pkg.devdir(),
|
||||
julia_version::VersionNumber=VERSION,
|
||||
ssh::Bool=false,
|
||||
manifest::Bool=false,
|
||||
plugins::Vector{<:Plugin}=Plugin[],
|
||||
)
|
||||
# Check for required Git options for package generation
|
||||
@ -79,7 +82,7 @@ create a template, you can use [`interactive_template`](@ref) instead.
|
||||
@warn "Plugin list contained duplicates, only the last of each type was kept"
|
||||
end
|
||||
|
||||
new(user, host, license, authors, dir, julia_version, ssh, plugin_dict)
|
||||
new(user, host, license, authors, dir, julia_version, ssh, manifest, plugin_dict)
|
||||
end
|
||||
end
|
||||
|
||||
@ -101,6 +104,7 @@ function Base.show(io::IO, t::Template)
|
||||
println(io, "$spc→ Package directory: $(replace(maybe(t.dir), homedir() => "~"))")
|
||||
println(io, "$spc→ Minimum Julia version: v$(version_floor(t.julia_version))")
|
||||
println(io, "$spc→ SSH remote: $(t.ssh ? "Yes" : "No")")
|
||||
println(io, "$spc→ Commit Manifest.toml: $(t.manifest ? "Yes" : "No")")
|
||||
|
||||
print(io, "$spc→ Plugins:")
|
||||
if isempty(t.plugins)
|
||||
@ -130,7 +134,7 @@ function interactive_template(; fast::Bool=false)
|
||||
kwargs = Dict{Symbol, Any}()
|
||||
|
||||
default_user = LibGit2.getconfig("github.user", "")
|
||||
print("Enter your username [$(isempty(default_user) ? "REQUIRED" : default_user)]: ")
|
||||
print("Username [$(isempty(default_user) ? "REQUIRED" : default_user)]: ")
|
||||
user = readline()
|
||||
kwargs[:user] = if !isempty(user)
|
||||
user
|
||||
@ -144,7 +148,7 @@ function interactive_template(; fast::Bool=false)
|
||||
"https://github.com"
|
||||
else
|
||||
default_host = "github.com"
|
||||
print("Enter the code hosting service [$default_host]: ")
|
||||
print("Code hosting service [$default_host]: ")
|
||||
host = readline()
|
||||
isempty(host) ? default_host : host
|
||||
end
|
||||
@ -152,7 +156,7 @@ function interactive_template(; fast::Bool=false)
|
||||
kwargs[:license] = if fast
|
||||
"MIT"
|
||||
else
|
||||
println("Select a license:")
|
||||
println("License:")
|
||||
io = IOBuffer()
|
||||
available_licenses(io)
|
||||
licenses = ["" => "", collect(LICENSES)...]
|
||||
@ -169,7 +173,7 @@ function interactive_template(; fast::Bool=false)
|
||||
else
|
||||
default_authors = LibGit2.getconfig("user.name", "")
|
||||
default_str = isempty(default_authors) ? "None" : default_authors
|
||||
print("Enter the package author(s) [$default_str]: ")
|
||||
print("Package author(s) [$default_str]: ")
|
||||
authors = readline()
|
||||
isempty(authors) ? default_authors : authors
|
||||
end
|
||||
@ -178,7 +182,7 @@ function interactive_template(; fast::Bool=false)
|
||||
Pkg.devdir()
|
||||
else
|
||||
default_dir = Pkg.devdir()
|
||||
print("Enter the path to the package directory [$default_dir]: ")
|
||||
print("Path to package directory [$default_dir]: ")
|
||||
dir = readline()
|
||||
isempty(dir) ? default_dir : dir
|
||||
end
|
||||
@ -187,7 +191,7 @@ function interactive_template(; fast::Bool=false)
|
||||
VERSION
|
||||
else
|
||||
default_julia_version = VERSION
|
||||
print("Enter the minimum Julia version [$(version_floor(default_julia_version))]: ")
|
||||
print("Mminimum Julia version [$(version_floor(default_julia_version))]: ")
|
||||
julia_version = readline()
|
||||
isempty(julia_version) ? default_julia_version : VersionNumber(julia_version)
|
||||
end
|
||||
@ -196,10 +200,17 @@ function interactive_template(; fast::Bool=false)
|
||||
false
|
||||
else
|
||||
print("Set remote to SSH? [no]: ")
|
||||
in(uppercase(readline()), ["Y", "YES", "T", "TRUE"])
|
||||
uppercase(readline()) in ["Y", "YES", "T", "TRUE"]
|
||||
end
|
||||
|
||||
println("Select plugins:")
|
||||
kwargs[:manifest] = if fast
|
||||
false
|
||||
else
|
||||
print("Commit Manifest.toml? [no]: ")
|
||||
uppercase(readline()) in ["Y", "YES", "T", "TRUE"]
|
||||
end
|
||||
|
||||
println("Plugins:")
|
||||
# Only include plugin types which have an `interactive` method.
|
||||
plugin_types = filter(t -> hasmethod(interactive, (Type{t},)), fetch(plugin_types))
|
||||
type_names = map(t -> split(string(t), ".")[end], plugin_types)
|
||||
|
@ -1,6 +1,6 @@
|
||||
@testset "Interactive mode" begin
|
||||
@testset "Template creation" begin
|
||||
write(stdin.buffer, "$me\n\n\r\n\n\nd")
|
||||
write(stdin.buffer, "$me\n\n\r\n\n\n\nd")
|
||||
t = interactive_template()
|
||||
@test t.user == me
|
||||
@test t.host == "github.com"
|
||||
@ -17,7 +17,7 @@
|
||||
end
|
||||
|
||||
down = '\x1b' * "[B" # Down array key.
|
||||
write(stdin.buffer, "$me\ngitlab.com\n$down\r$me\n$test_file\n0.5\nyes\n$down\r$down\rd\n\n")
|
||||
write(stdin.buffer, "$me\ngitlab.com\n$down\r$me\n$test_file\n0.5\nyes\nyes\n$down\r$down\rd\n\n")
|
||||
t = interactive_template()
|
||||
@test t.user == me
|
||||
@test t.host == "gitlab.com"
|
||||
@ -27,6 +27,7 @@
|
||||
@test t.dir == abspath(test_file)
|
||||
@test t.julia_version == v"0.5.0"
|
||||
@test t.ssh
|
||||
@test t.manifest
|
||||
# Like above, not sure which plugins this will generate.
|
||||
@test length(t.plugins) == 2
|
||||
|
||||
@ -39,12 +40,13 @@
|
||||
@test t.dir == default_dir
|
||||
@test t.julia_version == VERSION
|
||||
@test !t.ssh
|
||||
@test !t.manifest
|
||||
@test isempty(t.plugins)
|
||||
println()
|
||||
end
|
||||
|
||||
@testset "Package generation" begin
|
||||
write(stdin.buffer, "$me\n\n\r\n\n\n\n\n\nd")
|
||||
write(stdin.buffer, "$me\n\n\r\n\n\n\n\n\n\nd")
|
||||
generate_interactive(test_pkg; gitconfig=gitconfig)
|
||||
@test isdir(joinpath(default_dir, test_pkg))
|
||||
rm(joinpath(default_dir, test_pkg); force=true, recursive=true)
|
||||
|
@ -45,6 +45,8 @@ write(test_file, template_text)
|
||||
@test t.authors == LibGit2.getconfig("user.name", "")
|
||||
@test t.dir == default_dir
|
||||
@test t.julia_version == VERSION
|
||||
@test !t.ssh
|
||||
@test !t.manifest
|
||||
@test isempty(t.plugins)
|
||||
|
||||
# Checking non-default field assignments.
|
||||
@ -72,6 +74,12 @@ write(test_file, template_text)
|
||||
t = Template(; user=me, julia_version=v"0.1.2")
|
||||
@test t.julia_version == v"0.1.2"
|
||||
|
||||
t = Template(; user=me, ssh=true)
|
||||
@test t.ssh
|
||||
|
||||
t = Template(; user=me, manifest=true)
|
||||
@test t.manifest
|
||||
|
||||
# The template should contain whatever plugins you give it.
|
||||
t = Template(;
|
||||
user=me,
|
||||
@ -114,6 +122,7 @@ end
|
||||
→ Package directory: $pkg_dir
|
||||
→ Minimum Julia version: v$(PkgTemplates.version_floor())
|
||||
→ SSH remote: No
|
||||
→ Commit Manifest.toml: No
|
||||
→ Plugins: None
|
||||
"""
|
||||
@test text == rstrip(expected)
|
||||
@ -121,6 +130,7 @@ end
|
||||
user=me,
|
||||
license="",
|
||||
ssh=true,
|
||||
manifest=true,
|
||||
plugins=[
|
||||
TravisCI(),
|
||||
Codecov(),
|
||||
@ -137,6 +147,7 @@ end
|
||||
→ Package directory: $pkg_dir
|
||||
→ Minimum Julia version: v$(PkgTemplates.version_floor())
|
||||
→ SSH remote: Yes
|
||||
→ Commit Manifest.toml: Yes
|
||||
→ Plugins:
|
||||
• Codecov:
|
||||
→ Config file: None
|
||||
@ -186,10 +197,7 @@ end
|
||||
gen_readme(pkg_dir, t)
|
||||
readme = readchomp(joinpath(pkg_dir, "README.md"))
|
||||
rm(joinpath(pkg_dir, "README.md"))
|
||||
@test <(
|
||||
something(findfirst("coveralls", readme)).start,
|
||||
something(findfirst("baz", readme)).start,
|
||||
)
|
||||
@test findfirst("coveralls", readme).start < findfirst("baz", readme).start
|
||||
|
||||
# Test the gitignore generation.
|
||||
@test gen_gitignore(pkg_dir, t) == [".gitignore"]
|
||||
@ -197,11 +205,17 @@ end
|
||||
gitignore = read(joinpath(pkg_dir, ".gitignore"), String)
|
||||
rm(joinpath(pkg_dir, ".gitignore"))
|
||||
@test occursin(".DS_Store", gitignore)
|
||||
@test occursin("Manifest.toml", gitignore)
|
||||
for p in values(t.plugins)
|
||||
for entry in p.gitignore
|
||||
@test occursin(entry, gitignore)
|
||||
end
|
||||
end
|
||||
t = Template(; user=me, manifest=true)
|
||||
@test gen_gitignore(pkg_dir, t) == [".gitignore", "Manifest.toml"]
|
||||
gitignore = read(joinpath(pkg_dir, ".gitignore"), String)
|
||||
@test !occursin("Manifest.toml", gitignore)
|
||||
rm(joinpath(pkg_dir, ".gitignore"))
|
||||
|
||||
# Test the license generation.
|
||||
@test gen_license(pkg_dir, t) == ["LICENSE"]
|
||||
@ -219,7 +233,7 @@ end
|
||||
rm(joinpath(pkg_dir, "REQUIRE"))
|
||||
|
||||
# Test the test generation.
|
||||
@test gen_tests(pkg_dir, t) == ["Manifest.toml", "test/"]
|
||||
@test gen_tests(pkg_dir, t) == ["test/"]
|
||||
@test isfile(joinpath(pkg_dir, "Project.toml"))
|
||||
project = read(joinpath(pkg_dir, "Project.toml"), String)
|
||||
@test occursin("[extras]\nTest = ", project)
|
||||
@ -285,6 +299,26 @@ end
|
||||
generate(test_pkg, t; gitconfig=gitconfig)
|
||||
@test isdir(joinpath(temp_dir, test_pkg))
|
||||
rm(temp_dir; recursive=true)
|
||||
|
||||
# Check that the Manifest.toml is not commited by default.
|
||||
t = Template(; user=me)
|
||||
generate(test_pkg, t; gitconfig=gitconfig)
|
||||
@test occursin("Manifest.toml", read(joinpath(pkg_dir, ".gitignore"), String))
|
||||
# I'm not sure this is the "right" way to do this.
|
||||
repo = GitRepo(pkg_dir)
|
||||
idx = LibGit2.GitIndex(repo)
|
||||
@test findall("Manifest.toml", idx) === nothing
|
||||
rm(pkg_dir; recursive=true)
|
||||
|
||||
# And that it is when you tell it to be.
|
||||
t = Template(; user=me, manifest=true)
|
||||
generate(test_pkg, t; gitconfig=gitconfig)
|
||||
@test !occursin("Manifest.toml", read(joinpath(pkg_dir, ".gitignore"), String))
|
||||
# I'm not sure this is the "right" way to do this.
|
||||
repo = GitRepo(pkg_dir)
|
||||
idx = LibGit2.GitIndex(repo)
|
||||
@test findall("Manifest.toml", idx) !== nothing
|
||||
rm(pkg_dir; recursive=true)
|
||||
end
|
||||
|
||||
@testset "Version floor" begin
|
||||
|
Loading…
Reference in New Issue
Block a user