Skip to content

Commit 24376f8

Browse files
committed
fix pin on repo added packages (#268)
* fix pin on repo added packages * more pin free fixes
1 parent a221e91 commit 24376f8

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

stdlib/Pkg3/src/API.jl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,22 @@ function free(ctx::Context, pkgs::Vector{PackageSpec}; kwargs...)
176176
Context!(ctx; kwargs...)
177177
ctx.preview && preview_info()
178178
registry_resolve!(ctx.env, pkgs)
179-
ensure_resolved(ctx.env, pkgs; registry=true)
179+
uuids_in_registry = UUID[]
180+
for pkg in pkgs
181+
pkg.mode = PKGMODE_MANIFEST
182+
end
183+
for pkg in pkgs
184+
has_uuid(pkg) && push!(uuids_in_registry, pkg.uuid)
185+
end
186+
manifest_resolve!(ctx.env, pkgs)
187+
ensure_resolved(ctx.env, pkgs)
188+
# Every non pinned package that is freed need to be in a registry
189+
for pkg in pkgs
190+
info = manifest_info(ctx.env, pkg.uuid)
191+
if !get(info, "pinned", false) && !(pkg.uuid in uuids_in_registry)
192+
cmderror("cannot free an unpinned package that does not exist in a registry")
193+
end
194+
end
180195
Operations.free(ctx, pkgs)
181196
return
182197
end

stdlib/Pkg3/src/Operations.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function collect_fixed!(ctx::Context, pkgs::Vector{PackageSpec}, uuid_to_name::D
8080
for pkg in pkgs
8181
local path
8282
info = manifest_info(ctx.env, pkg.uuid)
83-
if pkg.special_action == PKGSPEC_FREED
83+
if pkg.special_action == PKGSPEC_FREED && !haskey(info, "pinned")
8484
continue
8585
elseif pkg.special_action == PKGSPEC_DEVELOPED
8686
@assert pkg.path !== nothing
@@ -596,17 +596,25 @@ function update_manifest(ctx::Context, pkg::PackageSpec, hash::Union{SHA1, Nothi
596596
info["version"] = string(version)
597597
hash == nothing ? delete!(info, "git-tree-sha1") : (info["git-tree-sha1"] = string(hash))
598598
path == nothing ? delete!(info, "path") : (info["path"] = relative_project_path_if_in_project(ctx, path))
599-
if special_action in (PKGSPEC_FREED, PKGSPEC_DEVELOPED)
599+
if special_action == PKGSPEC_DEVELOPED
600600
delete!(info, "pinned")
601601
delete!(info, "repo-url")
602602
delete!(info, "repo-rev")
603+
elseif special_action == PKGSPEC_FREED
604+
if get(info, "pinned", false)
605+
delete!(info, "pinned")
606+
else
607+
delete!(info, "repo-url")
608+
delete!(info, "repo-rev")
609+
end
603610
elseif special_action == PKGSPEC_PINNED
604611
info["pinned"] = true
605612
elseif special_action == PKGSPEC_REPO_ADDED
606613
info["repo-url"] = repo.url
607614
info["repo-rev"] = repo.rev
608615
path = find_installed(name, uuid, hash)
609-
elseif haskey(info, "repo-url")
616+
end
617+
if haskey(info, "repo-url")
610618
path = find_installed(name, uuid, hash)
611619
end
612620

stdlib/Pkg3/src/REPLMode.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ What action you want the package manager to take:
339339
340340
`develop`: clone the full package repo locally for development
341341
342-
`free`: undoes a `pin` or `develop`
342+
`free`: undoes a `pin`, `develop`, or stops tracking a repo.
343343
344344
`precompile`: precompile all the project dependencies
345345
"""

stdlib/Pkg3/test/repl.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ temp_pkg_dir() do project_path; cd(project_path) do; mktempdir() do tmp_pkg_path
6464
pkg2 = "UnregisteredWithProject"
6565
p2 = git_init_package(tmp_pkg_path, joinpath(@__DIR__, "test_packages/$pkg2"))
6666
Pkg3.REPLMode.pkgstr("add $p2")
67+
Pkg3.REPLMode.pkgstr("pin $pkg2")
6768
@eval import $(Symbol(pkg2))
6869
@test Pkg3.installed()[pkg2] == v"0.1.0"
70+
Pkg3.REPLMode.pkgstr("free $pkg2")
71+
@test_throws CommandError Pkg3.REPLMode.pkgstr("free $pkg2")
6972
Pkg3.test("UnregisteredWithProject")
7073

7174
write(joinpath(p2, "Project.toml"), """

0 commit comments

Comments
 (0)