Skip to content

Commit

Permalink
Warn if imported pkgs are updated. Fix #18239 (#18248)
Browse files Browse the repository at this point in the history
Add test for #18248.

Remove redundant loop.

Refactor test.

Wrap line.
  • Loading branch information
helgee authored and tkelman committed Sep 8, 2016
1 parent fd679b9 commit 424b3c5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions base/pkg/entry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
19 changes: 19 additions & 0 deletions test/pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 424b3c5

Please sign in to comment.