diff --git a/base/pkg/entry.jl b/base/pkg/entry.jl index 6a0cf4dda1f6b..48d94c8113101 100644 --- a/base/pkg/entry.jl +++ b/base/pkg/entry.jl @@ -523,6 +523,7 @@ function resolve( # try applying changes, roll back everything if anything fails changed = [] + imported = String[] try for (pkg,(ver1,ver2)) in changes if ver1 === nothing @@ -535,6 +536,10 @@ function resolve( up = ver1 <= ver2 ? "Up" : "Down" info("$(up)grading $pkg: v$ver1 => v$ver2") Write.update(pkg, Read.sha1(pkg,ver2)) + pkgsym = Symbol(pkg) + if isdefined(Main, pkgsym) && isa(getfield(Main, pkgsym), Module) + push!(imported, "- $pkg") + end end push!(changed,(pkg,(ver1,ver2))) end @@ -553,6 +558,10 @@ function resolve( end rethrow(err) end + if !isempty(imported) + warn(join(["The following packages have been updated but were already imported:", + imported..., "Restart Julia to use the updated versions."], "\n")) + end # re/build all updated/installed packages build(map(x->x[1], filter(x -> x[2][2] !== nothing, changes))) end diff --git a/test/pkg.jl b/test/pkg.jl index c685c66cd17bb..1b47ed74c3707 100644 --- a/test/pkg.jl +++ b/test/pkg.jl @@ -541,4 +541,23 @@ temp_pkg_dir() do @test ret === nothing && out == "" @test contains(err, nothingtodomsg) end + + # issue #18239 + let package = "Example" + Pkg.free(package) + Pkg.rm(package) # Remove package if installed + + metadata_dir = Pkg.dir("METADATA") + const old_commit = "83ff7116e51fc9cdbd7e67affbd344b9f5c9dbf2" + + # Reset METADATA to the second to last update of Example.jl + LibGit2.with(LibGit2.GitRepo, metadata_dir) do repo + LibGit2.reset!(repo, LibGit2.Oid(old_commit), LibGit2.Consts.RESET_HARD) + end + + Pkg.add(package) + msg = readstring(ignorestatus(`$(Base.julia_cmd()) --startup-file=no -e + "redirect_stderr(STDOUT); using Example; Pkg.update(\"$package\")"`)) + @test contains(msg, "- $package\nRestart Julia to use the updated versions.") + end end