Skip to content

Commit

Permalink
make free --all not error if some are free already (#2939)
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth authored Jan 14, 2022
1 parent 1b9c0c0 commit f60f1cd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 7 additions & 4 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions test/new.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit f60f1cd

Please sign in to comment.