Skip to content

Commit

Permalink
fix pin on repo added packages (#268)
Browse files Browse the repository at this point in the history
* fix pin on repo added packages

* more pin free fixes
  • Loading branch information
KristofferC committed May 9, 2018
1 parent a221e91 commit 24376f8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
17 changes: 16 additions & 1 deletion stdlib/Pkg3/src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,22 @@ function free(ctx::Context, pkgs::Vector{PackageSpec}; kwargs...)
Context!(ctx; kwargs...)
ctx.preview && preview_info()
registry_resolve!(ctx.env, pkgs)
ensure_resolved(ctx.env, pkgs; registry=true)
uuids_in_registry = UUID[]
for pkg in pkgs
pkg.mode = PKGMODE_MANIFEST
end
for pkg in pkgs
has_uuid(pkg) && push!(uuids_in_registry, pkg.uuid)
end
manifest_resolve!(ctx.env, pkgs)
ensure_resolved(ctx.env, pkgs)
# Every non pinned package that is freed need to be in a registry
for pkg in pkgs
info = manifest_info(ctx.env, pkg.uuid)
if !get(info, "pinned", false) && !(pkg.uuid in uuids_in_registry)
cmderror("cannot free an unpinned package that does not exist in a registry")
end
end
Operations.free(ctx, pkgs)
return
end
Expand Down
14 changes: 11 additions & 3 deletions stdlib/Pkg3/src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function collect_fixed!(ctx::Context, pkgs::Vector{PackageSpec}, uuid_to_name::D
for pkg in pkgs
local path
info = manifest_info(ctx.env, pkg.uuid)
if pkg.special_action == PKGSPEC_FREED
if pkg.special_action == PKGSPEC_FREED && !haskey(info, "pinned")
continue
elseif pkg.special_action == PKGSPEC_DEVELOPED
@assert pkg.path !== nothing
Expand Down Expand Up @@ -596,17 +596,25 @@ function update_manifest(ctx::Context, pkg::PackageSpec, hash::Union{SHA1, Nothi
info["version"] = string(version)
hash == nothing ? delete!(info, "git-tree-sha1") : (info["git-tree-sha1"] = string(hash))
path == nothing ? delete!(info, "path") : (info["path"] = relative_project_path_if_in_project(ctx, path))
if special_action in (PKGSPEC_FREED, PKGSPEC_DEVELOPED)
if special_action == PKGSPEC_DEVELOPED
delete!(info, "pinned")
delete!(info, "repo-url")
delete!(info, "repo-rev")
elseif special_action == PKGSPEC_FREED
if get(info, "pinned", false)
delete!(info, "pinned")
else
delete!(info, "repo-url")
delete!(info, "repo-rev")
end
elseif special_action == PKGSPEC_PINNED
info["pinned"] = true
elseif special_action == PKGSPEC_REPO_ADDED
info["repo-url"] = repo.url
info["repo-rev"] = repo.rev
path = find_installed(name, uuid, hash)
elseif haskey(info, "repo-url")
end
if haskey(info, "repo-url")
path = find_installed(name, uuid, hash)
end

Expand Down
2 changes: 1 addition & 1 deletion stdlib/Pkg3/src/REPLMode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ What action you want the package manager to take:
`develop`: clone the full package repo locally for development
`free`: undoes a `pin` or `develop`
`free`: undoes a `pin`, `develop`, or stops tracking a repo.
`precompile`: precompile all the project dependencies
"""
Expand Down
3 changes: 3 additions & 0 deletions stdlib/Pkg3/test/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ temp_pkg_dir() do project_path; cd(project_path) do; mktempdir() do tmp_pkg_path
pkg2 = "UnregisteredWithProject"
p2 = git_init_package(tmp_pkg_path, joinpath(@__DIR__, "test_packages/$pkg2"))
Pkg3.REPLMode.pkgstr("add $p2")
Pkg3.REPLMode.pkgstr("pin $pkg2")
@eval import $(Symbol(pkg2))
@test Pkg3.installed()[pkg2] == v"0.1.0"
Pkg3.REPLMode.pkgstr("free $pkg2")
@test_throws CommandError Pkg3.REPLMode.pkgstr("free $pkg2")
Pkg3.test("UnregisteredWithProject")

write(joinpath(p2, "Project.toml"), """
Expand Down

0 comments on commit 24376f8

Please sign in to comment.