Add error handling for invalid package directories
This commit is contained in:
parent
67eb1393a2
commit
8d9ce7a02b
@ -89,7 +89,15 @@ function generate(
|
|||||||
info("Committed files generated by PkgTemplates")
|
info("Committed files generated by PkgTemplates")
|
||||||
multiple_branches = length(collect(LibGit2.GitBranchIter(repo))) > 1
|
multiple_branches = length(collect(LibGit2.GitBranchIter(repo))) > 1
|
||||||
info("Moving temporary package directory into $(t.dir)/")
|
info("Moving temporary package directory into $(t.dir)/")
|
||||||
|
try
|
||||||
|
mkpath(dirname(pkg_dir))
|
||||||
mv(temp_pkg_dir, pkg_dir; remove_destination=force)
|
mv(temp_pkg_dir, pkg_dir; remove_destination=force)
|
||||||
|
catch # Likely cause is that t.path can't be created (is a file, etc.).
|
||||||
|
# We need another temporary directory because temp_pkg_dir is about to be removed.
|
||||||
|
temp_dir = mktempdir()
|
||||||
|
mv(temp_pkg_dir, joinpath(temp_dir, pkg_name))
|
||||||
|
warn("$pkg_name couldn't be moved into $pkg_dir, left package in $temp_dir")
|
||||||
|
end
|
||||||
|
|
||||||
info("Finished")
|
info("Finished")
|
||||||
if multiple_branches
|
if multiple_branches
|
||||||
|
@ -24,7 +24,8 @@ create a template, you can use [`interactive_template`](@ref) instead.
|
|||||||
git config's value, if it is left unset.
|
git config's value, if it is left unset.
|
||||||
* `years::Union{Integer, AbstractString}=Dates.year(Dates.today())`: Copyright years on the
|
* `years::Union{Integer, AbstractString}=Dates.year(Dates.today())`: Copyright years on the
|
||||||
license. Can be supplied by a number, or a string such as "2016 - 2017".
|
license. Can be supplied by a number, or a string such as "2016 - 2017".
|
||||||
* `dir::AbstractString=Pkg.dir()`: Directory in which the package will go.
|
* `dir::AbstractString=Pkg.dir()`: Directory in which the package will go. Relative paths
|
||||||
|
are converted to absolute ones at template creation time.
|
||||||
* `julia_version::VersionNumber=VERSION`: Minimum allowed Julia version.
|
* `julia_version::VersionNumber=VERSION`: Minimum allowed Julia version.
|
||||||
* `requirements::Vector{String}=String[]`: Package requirements. If there are duplicate
|
* `requirements::Vector{String}=String[]`: Package requirements. If there are duplicate
|
||||||
requirements with different versions, i.e. ["PkgTemplates", "PkgTemplates 0.1"],
|
requirements with different versions, i.e. ["PkgTemplates", "PkgTemplates 0.1"],
|
||||||
@ -100,7 +101,7 @@ create a template, you can use [`interactive_template`](@ref) instead.
|
|||||||
end
|
end
|
||||||
|
|
||||||
new(
|
new(
|
||||||
user, host, license, authors, years, dir, julia_version,
|
user, host, license, authors, years, abspath(dir), julia_version,
|
||||||
requirements_dedup, gitconfig, plugin_dict,
|
requirements_dedup, gitconfig, plugin_dict,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
@test !isempty(t.license)
|
@test !isempty(t.license)
|
||||||
@test t.authors == me
|
@test t.authors == me
|
||||||
@test t.years == "2016"
|
@test t.years == "2016"
|
||||||
@test t.dir == test_file
|
@test t.dir == abspath(test_file)
|
||||||
@test t.julia_version == v"0.5.0"
|
@test t.julia_version == v"0.5.0"
|
||||||
@test Set(t.requirements) == Set(["X", "Y"])
|
@test Set(t.requirements) == Set(["X", "Y"])
|
||||||
@test t.gitconfig == Dict("A" => "B")
|
@test t.gitconfig == Dict("A" => "B")
|
||||||
|
@ -60,7 +60,7 @@ write(test_file, template_text)
|
|||||||
@test t.authors == "Guy, Gal"
|
@test t.authors == "Guy, Gal"
|
||||||
|
|
||||||
t = Template(; user=me, dir=test_file)
|
t = Template(; user=me, dir=test_file)
|
||||||
@test t.dir == test_file
|
@test t.dir == abspath(test_file)
|
||||||
|
|
||||||
t = Template(; user=me, julia_version=v"0.1.2")
|
t = Template(; user=me, julia_version=v"0.1.2")
|
||||||
@test t.julia_version == v"0.1.2"
|
@test t.julia_version == v"0.1.2"
|
||||||
@ -377,6 +377,13 @@ end
|
|||||||
@test isfile(Pkg.dir(test_pkg, "README.md"))
|
@test isfile(Pkg.dir(test_pkg, "README.md"))
|
||||||
rm(Pkg.dir(test_pkg); recursive=true)
|
rm(Pkg.dir(test_pkg); recursive=true)
|
||||||
|
|
||||||
|
# Note: These tests will leave temporary directories on disk.
|
||||||
|
temp_file = mktemp()[1]
|
||||||
|
t = Template(; user=me, dir=temp_file, gitconfig=gitconfig)
|
||||||
|
@test_warn r".+" generate(test_pkg, t)
|
||||||
|
t = Template(; user=me, dir=joinpath(temp_file, temp_file), gitconfig=gitconfig)
|
||||||
|
@test_warn r".+" generate(test_pkg, t)
|
||||||
|
|
||||||
t = Template(; user=me, gitconfig=gitconfig, plugins=[GitHubPages()])
|
t = Template(; user=me, gitconfig=gitconfig, plugins=[GitHubPages()])
|
||||||
generate(test_pkg, t)
|
generate(test_pkg, t)
|
||||||
readme = readstring(Pkg.dir(test_pkg, "README.md"))
|
readme = readstring(Pkg.dir(test_pkg, "README.md"))
|
||||||
|
Loading…
Reference in New Issue
Block a user