diff --git a/src/API.jl b/src/API.jl index 4bb75ff974..51bbd92648 100644 --- a/src/API.jl +++ b/src/API.jl @@ -403,7 +403,7 @@ function free(ctx::Context, pkgs::Vector{PackageSpec}; all_pkgs::Bool=false, kwa manifest_resolve!(ctx.env.manifest, pkgs) ensure_resolved(ctx.env.manifest, pkgs) - Operations.free(ctx, pkgs) + Operations.free(ctx, pkgs; err_if_free = !all_pkgs) return end diff --git a/src/Operations.jl b/src/Operations.jl index d398211a5a..294b29bcbc 100644 --- a/src/Operations.jl +++ b/src/Operations.jl @@ -1355,7 +1355,7 @@ function pin(ctx::Context, pkgs::Vector{PackageSpec}) build_versions(ctx, new) end -function update_package_free!(registries::Vector{Registry.RegistryInstance}, pkg::PackageSpec, entry::PackageEntry) +function update_package_free!(registries::Vector{Registry.RegistryInstance}, pkg::PackageSpec, entry::PackageEntry, err_if_free::Bool) if entry.pinned pkg.pinned = false is_stdlib(pkg.uuid) && return # nothing left to do @@ -1371,14 +1371,17 @@ function update_package_free!(registries::Vector{Registry.RegistryInstance}, pkg end return # -> name, uuid end - pkgerror("expected package $(err_rep(pkg)) to be pinned, tracking a path,", + if err_if_free + pkgerror("expected package $(err_rep(pkg)) to be pinned, tracking a path,", " or tracking a repository") + end + return end # TODO: this is two techinically different operations with the same name # split into two subfunctions ... -function free(ctx::Context, pkgs::Vector{PackageSpec}) - foreach(pkg -> update_package_free!(ctx.registries, pkg, manifest_info(ctx.env.manifest, pkg.uuid)), pkgs) +function free(ctx::Context, pkgs::Vector{PackageSpec}; err_if_free=true) + foreach(pkg -> update_package_free!(ctx.registries, pkg, manifest_info(ctx.env.manifest, pkg.uuid), err_if_free), pkgs) if any(pkg -> pkg.version == VersionSpec(), pkgs) pkgs = load_direct_deps(ctx.env, pkgs) diff --git a/test/new.jl b/test/new.jl index 6d615919c2..50ed92e5e9 100644 --- a/test/new.jl +++ b/test/new.jl @@ -1867,6 +1867,9 @@ end @test pkg.name == "Example" @test !pkg.is_pinned end + Pkg.add("Profile") + Pkg.pin("Example") + Pkg.free(all_pkgs = true) # test that this doesn't error because Profile is already free Pkg.rm(all_pkgs = true) @test !haskey(Pkg.dependencies(), exuuid)