diff --git a/base/pkg/entry.jl b/base/pkg/entry.jl index ad160ae956b9a..78b1df245aafc 100644 --- a/base/pkg/entry.jl +++ b/base/pkg/entry.jl @@ -237,31 +237,6 @@ function checkout(pkg::AbstractString, branch::AbstractString, do_merge::Bool, d end end -function free(pkg::AbstractString) - ispath(pkg,".git") || throw(PkgError("$pkg is not a git repo")) - Read.isinstalled(pkg) || throw(PkgError("$pkg cannot be freed – not an installed package")) - avail = Read.available(pkg) - isempty(avail) && throw(PkgError("$pkg cannot be freed – not a registered package")) - with(GitRepo, pkg) do repo - LibGit2.isdirty(repo) && throw(PkgError("$pkg cannot be freed – repo is dirty")) - info("Freeing $pkg") - vers = sort!(collect(keys(avail)), rev=true) - while true - for ver in vers - sha1 = avail[ver].sha1 - LibGit2.iscommit(sha1, repo) || continue - return LibGit2.transact(repo) do r - LibGit2.isdirty(repo) && throw(PkgError("$pkg is dirty, bailing")) - LibGit2.checkout!(repo, sha1) - resolve() - end - end - isempty(Cache.prefetch(pkg, Read.url(pkg), [a.sha1 for (v,a)=avail])) && continue - throw(PkgError("can't find any registered versions of $pkg to checkout")) - end - end -end - function free(pkgs) try for pkg in pkgs @@ -280,6 +255,9 @@ function free(pkgs) break end end + # Add package to REQUIRE if it wasn't present already + # so that resolve() does not remove it + edit(Reqs.add, pkg) isempty(Cache.prefetch(pkg, Read.url(pkg), [a.sha1 for (v,a)=avail])) && continue throw(PkgError("Can't find any registered versions of $pkg to checkout")) end @@ -288,6 +266,8 @@ function free(pkgs) end end +free(pkg::AbstractString) = free([pkg]) + function pin(pkg::AbstractString, head::AbstractString) ispath(pkg,".git") || throw(PkgError("$pkg is not a git repo")) should_resolve = true diff --git a/test/pkg.jl b/test/pkg.jl index 4d2548f253d87..d1e8f39312caa 100644 --- a/test/pkg.jl +++ b/test/pkg.jl @@ -675,3 +675,19 @@ temp_pkg_dir(initialize=false) do "INFO: Building Normal") Pkg.Entry.build!(["Exit", "Normal", "Exit", "Normal"], errors) end end + +@testset "issue #17994" begin + temp_pkg_dir() do + @test Pkg.installed("Example.jl") === nothing + Pkg.add("Example.jl") + @test [keys(Pkg.installed())...] == ["Example"] + Pkg.checkout("Example.jl") + Pkg.rm("Example.jl") + Pkg.free("Example.jl") + @test [keys(Pkg.installed())...] == ["Example"] + iob = IOBuffer() + Pkg.status("Example.jl", iob) + str = chomp(String(take!(iob))) + @test endswith(str, string(Pkg.installed("Example.jl"))) + end +end