Add compat with Julia 1.4
This commit is contained in:
parent
5aa0a87c35
commit
0fcbaa83bf
@ -80,12 +80,8 @@ function posthook(p::Git, ::Template, pkg_dir::AbstractString)
|
||||
LibGit2.with(GitRepo(pkg_dir)) do repo
|
||||
LibGit2.add!(repo, ".")
|
||||
msg = "Files generated by PkgTemplates"
|
||||
# TODO: Newer versions of Julia will not have Pkg.installed.
|
||||
installed = Pkg.installed()
|
||||
if haskey(installed, "PkgTemplates")
|
||||
ver = string(installed["PkgTemplates"])
|
||||
msg *= "\n\nPkgTemplates version: $ver"
|
||||
end
|
||||
v = version_of("PkgTemplates")
|
||||
v === nothing || (msg *= "\n\nPkgTemplates version: $v")
|
||||
commit(p, repo, pkg_dir, msg)
|
||||
end
|
||||
end
|
||||
@ -99,3 +95,14 @@ function commit(p::Git, repo::GitRepo, pkg_dir::AbstractString, msg::AbstractStr
|
||||
end
|
||||
|
||||
needs_username(::Git) = true
|
||||
|
||||
if isdefined(Pkg, :dependencies)
|
||||
function version_of(pkg::AbstractString)
|
||||
for p in values(Pkg.dependencies())
|
||||
p.name == pkg && return p.version
|
||||
end
|
||||
return nothing
|
||||
end
|
||||
else
|
||||
version_of(pkg::AbstractString) = get(Pkg.installed(), pkg, nothing)
|
||||
end
|
||||
|
@ -38,7 +38,7 @@
|
||||
@testset "Adds version to commit message" begin
|
||||
# We're careful to avoid a Pkg.update as it triggers Cassette#130.
|
||||
t = tpl(; disable_defaults=[Tests], plugins=[Git()])
|
||||
mock(Pkg.installed => () -> Dict("PkgTemplates" => v"1.2.3")) do _pi
|
||||
mock(PT.version_of => _p -> v"1.2.3") do _i
|
||||
with_pkg(t) do pkg
|
||||
pkg_dir = joinpath(t.dir, pkg)
|
||||
LibGit2.with(GitRepo(pkg_dir)) do repo
|
||||
|
@ -6,7 +6,7 @@ using Random: Random
|
||||
using Test: @test, @testset, @test_throws
|
||||
|
||||
using ReferenceTests: @test_reference
|
||||
using SimpleMock: Mock, mock
|
||||
using SimpleMock: mock
|
||||
using Suppressor: @suppress
|
||||
|
||||
using PkgTemplates
|
||||
@ -30,7 +30,9 @@ function with_pkg(f::Function, t::Template, pkg::AbstractString=pkgname())
|
||||
try
|
||||
f(pkg)
|
||||
finally
|
||||
haskey(Pkg.installed(), pkg) && @suppress Pkg.rm(pkg)
|
||||
# On 1.4, this sometimes won't work, but the error is that the package isn't installed.
|
||||
# We're going to delete the package directory anyways, so just ignore any errors.
|
||||
PT.version_of(pkg) === nothing || try @suppress Pkg.rm(pkg) catch; end
|
||||
rm(joinpath(t.dir, pkg); recursive=true, force=true)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user