From 026bd8666eb763abf766bf59aa9e1dd5ddf37d45 Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Tue, 24 Apr 2018 15:07:09 +0200 Subject: [PATCH 1/4] give refspecs to the registry (#258) --- stdlib/Pkg3/src/API.jl | 2 +- stdlib/Pkg3/src/GitTools.jl | 1 - stdlib/Pkg3/src/Types.jl | 7 ++++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/stdlib/Pkg3/src/API.jl b/stdlib/Pkg3/src/API.jl index 0947e812106f1..8a40ec3d6d2fb 100644 --- a/stdlib/Pkg3/src/API.jl +++ b/stdlib/Pkg3/src/API.jl @@ -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")) diff --git a/stdlib/Pkg3/src/GitTools.jl b/stdlib/Pkg3/src/GitTools.jl index dbf90dd5ee64d..e51cc1750c5da 100644 --- a/stdlib/Pkg3/src/GitTools.jl +++ b/stdlib/Pkg3/src/GitTools.jl @@ -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] diff --git a/stdlib/Pkg3/src/Types.jl b/stdlib/Pkg3/src/Types.jl index 667853b9be6d4..47d074b95d519 100644 --- a/stdlib/Pkg3/src/Types.jl +++ b/stdlib/Pkg3/src/Types.jl @@ -719,7 +719,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 From 2620370e004f934bdefa6d1917860cd7f12472f1 Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Tue, 24 Apr 2018 15:07:42 +0200 Subject: [PATCH 2/4] fix up on package with no manifest (#257) * fix up on package with no manifest * add debug stuff * wut * sigh * fixups --- stdlib/Pkg3/src/Operations.jl | 22 +++++++++++++--------- stdlib/Pkg3/test/pkg.jl | 15 +++++++++++++++ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/stdlib/Pkg3/src/Operations.jl b/stdlib/Pkg3/src/Operations.jl index acfc6d4caed1f..2439d60a1c690 100644 --- a/stdlib/Pkg3/src/Operations.jl +++ b/stdlib/Pkg3/src/Operations.jl @@ -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 diff --git a/stdlib/Pkg3/test/pkg.jl b/stdlib/Pkg3/test/pkg.jl index 4603572ceb513..a2b8a3eb48c33 100644 --- a/stdlib/Pkg3/test/pkg.jl +++ b/stdlib/Pkg3/test/pkg.jl @@ -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 From 88c342aadb0d33564a3583aa588a72f5fea6bacb Mon Sep 17 00:00:00 2001 From: Douglas Bates Date: Wed, 25 Apr 2018 09:37:28 -0500 Subject: [PATCH 3/4] Spelling --- stdlib/Pkg3/src/REPLMode.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/Pkg3/src/REPLMode.jl b/stdlib/Pkg3/src/REPLMode.jl index 7278b2c613766..a97b22417f8c6 100644 --- a/stdlib/Pkg3/src/REPLMode.jl +++ b/stdlib/Pkg3/src/REPLMode.jl @@ -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 """ From acb6cae3408ab17c4a0e122b4744f105197ccdc2 Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Wed, 25 Apr 2018 12:18:51 +0200 Subject: [PATCH 4/4] fix adding and developing detached repos --- stdlib/Pkg3/src/API.jl | 17 ++++++++++------- stdlib/Pkg3/src/Types.jl | 39 +++++++++++++++++++++++++++++---------- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/stdlib/Pkg3/src/API.jl b/stdlib/Pkg3/src/API.jl index 8a40ec3d6d2fb..d779b344fc729 100644 --- a/stdlib/Pkg3/src/API.jl +++ b/stdlib/Pkg3/src/API.jl @@ -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...) @@ -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...) diff --git a/stdlib/Pkg3/src/Types.jl b/stdlib/Pkg3/src/Types.jl index 47d074b95d519..57bab36b6ac8b 100644 --- a/stdlib/Pkg3/src/Types.jl +++ b/stdlib/Pkg3/src/Types.jl @@ -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...) @@ -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 @@ -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")) @@ -735,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 @@ -765,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) @@ -777,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)) @@ -796,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