Skip to content

Commit

Permalink
Merge pull request #26908 from JuliaLang/kc/bump_pkg3_7
Browse files Browse the repository at this point in the history
Bump Pkg3
  • Loading branch information
KristofferC authored Apr 26, 2018
2 parents 67fc4fc + acb6cae commit f4349c1
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 30 deletions.
19 changes: 11 additions & 8 deletions stdlib/Pkg3/src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function update_registry(ctx)
end
branch = LibGit2.headname(repo)
try
GitTools.fetch(repo)
GitTools.fetch(repo; refspecs=["+refs/heads/$branch:refs/remotes/origin/$branch"])
catch e
e isa LibGit2.GitError || rethrow(e)
push!(errors, (reg, "failed to fetch from repo"))
Expand Down Expand Up @@ -118,10 +118,10 @@ function update_registry(ctx)
return
end

up(;kwargs...) = up(PackageSpec[]; kwargs...)
up(pkg::Union{String, PackageSpec}; kwargs...) = up([pkg]; kwargs...)
up(pkgs::Vector{String}; kwargs...) = up([PackageSpec(pkg) for pkg in pkgs]; kwargs...)
up(pkgs::Vector{PackageSpec}; kwargs...) = up(Context(), pkgs; kwargs...)
up(;kwargs...) = up(PackageSpec[]; kwargs...)
up(pkg::Union{String, PackageSpec}; kwargs...) = up([pkg]; kwargs...)
up(pkgs::Vector{String}; kwargs...) = up([PackageSpec(pkg) for pkg in pkgs]; kwargs...)
up(pkgs::Vector{PackageSpec}; kwargs...) = up(Context(), pkgs; kwargs...)

function up(ctx::Context, pkgs::Vector{PackageSpec};
level::UpgradeLevel=UPLEVEL_MAJOR, mode::PackageMode=PKGMODE_PROJECT, kwargs...)
Expand Down Expand Up @@ -383,10 +383,13 @@ end
#####################################
# Backwards compatibility with Pkg2 #
#####################################

function clone(pkg::String...)
function clone(url::String, name::String = "")
@warn "Pkg.clone is only kept for legacy CI script reasons, please use `add`" maxlog=1
add(joinpath(pkg...))
ctx = Context()
if !isempty(name)
ctx.old_pkg2_clone_name = name
end
develop(ctx, [parse_package(url)])
end

function dir(pkg::String, paths::String...)
Expand Down
1 change: 0 additions & 1 deletion stdlib/Pkg3/src/GitTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ function showprogress(io::IO, p::MiniProgressBar)
end

function transfer_progress(progress::Ptr{LibGit2.TransferProgress}, p::Any)

progress = unsafe_load(progress)
@assert haskey(p, :transfer_progress)
bar = p[:transfer_progress]
Expand Down
22 changes: 13 additions & 9 deletions stdlib/Pkg3/src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -961,20 +961,24 @@ function up(ctx::Context, pkgs::Vector{PackageSpec})
pkg.version isa UpgradeLevel || continue
level = pkg.version
info = manifest_info(ctx.env, pkg.uuid)
if haskey(info, "repo-url")
if info !== nothing && haskey(info, "repo-url")
pkg.repo = Types.GitRepo(info["repo-url"], info["repo-rev"])
new = handle_repos_add!(ctx, [pkg]; upgrade_or_add = (level == UPLEVEL_MAJOR))
append!(new_git, new)
else
ver = VersionNumber(info["version"])
if level == UPLEVEL_FIXED
pkg.version = VersionNumber(info["version"])
if info !== nothing
ver = VersionNumber(info["version"])
if level == UPLEVEL_FIXED
pkg.version = VersionNumber(info["version"])
else
r = level == UPLEVEL_PATCH ? VersionRange(ver.major, ver.minor) :
level == UPLEVEL_MINOR ? VersionRange(ver.major) :
level == UPLEVEL_MAJOR ? VersionRange() :
error("unexpected upgrade level: $level")
pkg.version = VersionSpec(r)
end
else
r = level == UPLEVEL_PATCH ? VersionRange(ver.major, ver.minor) :
level == UPLEVEL_MINOR ? VersionRange(ver.major) :
level == UPLEVEL_MAJOR ? VersionRange() :
error("unexpected upgrade level: $level")
pkg.version = VersionSpec(r)
pkg.version = VersionSpec()
end
end
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`: undos a `pin` or `develop`
`free`: undoes a `pin` or `develop`
`precompile`: precompile all the project dependencies
"""
Expand Down
46 changes: 35 additions & 11 deletions stdlib/Pkg3/src/Types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,8 @@ Base.@kwdef mutable struct Context
num_concurrent_downloads::Int = 8
graph_verbose::Bool = false
stdlibs::Dict{UUID,String} = gather_stdlib_uuids()
# Remove next field when support for Pkg2 CI scripts is removed
old_pkg2_clone_name::String = ""
end

function Context!(ctx::Context; kwargs...)
Expand Down Expand Up @@ -652,7 +654,7 @@ function handle_repos_develop!(ctx::Context, pkgs::AbstractVector{PackageSpec})
pkg.path = abspath(pkg.repo.url)
folder_already_downloaded = true
project_path = pkg.repo.url
parse_package!(env, pkg, project_path)
parse_package!(ctx, pkg, project_path)
else
# We save the repo in case another environement wants to
# develop from the same repo, this avoids having to reclone it
Expand All @@ -675,11 +677,17 @@ function handle_repos_develop!(ctx::Context, pkgs::AbstractVector{PackageSpec})
cp(repo_path, project_path; force=true)
repo = LibGit2.GitRepo(project_path)
rev = pkg.repo.rev
isempty(rev) && (rev = LibGit2.branch(repo))
if isempty(rev)
if LibGit2.isattached(repo)
rev = LibGit2.branch(repo)
else
rev = string(LibGit2.GitHash(LibGit2.head(repo)))
end
end
gitobject, isbranch = checkout_rev!(repo, rev)
close(repo); close(gitobject)

parse_package!(env, pkg, project_path)
parse_package!(ctx, pkg, project_path)
dev_pkg_path = joinpath(Pkg3.devdir(), pkg.name)
if isdir(dev_pkg_path)
if !isfile(joinpath(dev_pkg_path, "src", pkg.name * ".jl"))
Expand Down Expand Up @@ -719,7 +727,12 @@ function handle_repos_add!(ctx::Context, pkgs::AbstractVector{PackageSpec}; upgr
pinned = (info != nothing && get(info, "pinned", false))
if upgrade_or_add && !pinned && !just_cloned
rev = pkg.repo.rev
GitTools.fetch(repo, pkg.repo.url; refspecs=refspecs, credentials=creds)
try
GitTools.fetch(repo, pkg.repo.url; refspecs=refspecs, credentials=creds)
catch e
e isa LibGit2.GitError || rethrow(e)
cmderror("failed to fetch from $(pkg.repo.url), error: $e")
end
end
if upgrade_or_add && !pinned
rev = pkg.repo.rev
Expand All @@ -730,7 +743,13 @@ function handle_repos_add!(ctx::Context, pkgs::AbstractVector{PackageSpec}; upgr
end

# see if we can get rev as a branch
isempty(rev) && (rev = LibGit2.branch(repo); pkg.repo.rev = rev)
if isempty(rev)
if LibGit2.isattached(repo)
rev = LibGit2.branch(repo)
else
rev = string(LibGit2.GitHash(LibGit2.head(repo)))
end
end
gitobject, isbranch = checkout_rev!(repo, rev)
if !isbranch
# If the user gave a shortened commit SHA, might as well update it to the full one
Expand Down Expand Up @@ -760,7 +779,7 @@ function handle_repos_add!(ctx::Context, pkgs::AbstractVector{PackageSpec}; upgr
LibGit2.checkout_tree(repo, git_tree, options=opts)
end
close(repo); close(git_tree); close(gitobject)
parse_package!(env, pkg, project_path)
parse_package!(ctx, pkg, project_path)
if !folder_already_downloaded
version_path = Pkg3.Operations.find_installed(pkg.name, pkg.uuid, pkg.repo.git_tree_sha1)
mkpath(version_path)
Expand All @@ -772,7 +791,8 @@ function handle_repos_add!(ctx::Context, pkgs::AbstractVector{PackageSpec}; upgr
return new_uuids
end

function parse_package!(env, pkg, project_path)
function parse_package!(ctx, pkg, project_path)
env = ctx.env
found_project_file = false
for projname in project_names
if isfile(joinpath(project_path, projname))
Expand All @@ -791,10 +811,14 @@ function parse_package!(env, pkg, project_path)
end
if !found_project_file
@warn "packages will require to have a [Julia]Project.toml file in the future"
# This is an old style package, get the name from the url.
m = match(reg_pkg, pkg.repo.url)
m === nothing && cmderror("cannot determine package name from URL: $(pkg.repo.url)")
pkg.name = m.captures[1]
if !isempty(ctx.old_pkg2_clone_name) # remove when legacy CI script support is removed
pkg.name = ctx.old_pkg2_clone_name
else
# This is an old style package, get the name from src/PackageName
m = match(reg_pkg, pkg.repo.url)
m === nothing && cmderror("cannot determine package name from URL: $(pkg.repo.url)")
pkg.name = m.captures[1]
end
reg_uuids = registered_uuids(env, pkg.name)
is_registered = !isempty(reg_uuids)
if !is_registered
Expand Down
15 changes: 15 additions & 0 deletions stdlib/Pkg3/test/pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,21 @@ temp_pkg_dir() do project_path
end
end
end

@testset "up in Project without manifest" begin
mktempdir() do dir
cp(joinpath(@__DIR__, "test_packages", "UnregisteredWithProject"), joinpath(dir, "UnregisteredWithProject"))
cd(joinpath(dir, "UnregisteredWithProject")) do
try
pushfirst!(LOAD_PATH, Base.parse_load_path("@"))
Pkg3.up()
@test haskey(Pkg3.installed(), "Example")
finally
popfirst!(LOAD_PATH)
end
end
end
end
end

temp_pkg_dir() do project_path
Expand Down

0 comments on commit f4349c1

Please sign in to comment.