Skip to content

Commit 73e39b3

Browse files
KristofferCKeno
authored andcommitted
fix adding and developing detached repos
1 parent 4dbe08f commit 73e39b3

File tree

2 files changed

+39
-17
lines changed

2 files changed

+39
-17
lines changed

stdlib/Pkg3/src/API.jl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ function update_registry(ctx)
118118
return
119119
end
120120

121-
up(;kwargs...) = up(PackageSpec[]; kwargs...)
122-
up(pkg::Union{String, PackageSpec}; kwargs...) = up([pkg]; kwargs...)
123-
up(pkgs::Vector{String}; kwargs...) = up([PackageSpec(pkg) for pkg in pkgs]; kwargs...)
124-
up(pkgs::Vector{PackageSpec}; kwargs...) = up(Context(), pkgs; kwargs...)
121+
up(;kwargs...) = up(PackageSpec[]; kwargs...)
122+
up(pkg::Union{String, PackageSpec}; kwargs...) = up([pkg]; kwargs...)
123+
up(pkgs::Vector{String}; kwargs...) = up([PackageSpec(pkg) for pkg in pkgs]; kwargs...)
124+
up(pkgs::Vector{PackageSpec}; kwargs...) = up(Context(), pkgs; kwargs...)
125125

126126
function up(ctx::Context, pkgs::Vector{PackageSpec};
127127
level::UpgradeLevel=UPLEVEL_MAJOR, mode::PackageMode=PKGMODE_PROJECT, kwargs...)
@@ -383,10 +383,13 @@ end
383383
#####################################
384384
# Backwards compatibility with Pkg2 #
385385
#####################################
386-
387-
function clone(pkg::String...)
386+
function clone(url::String, name::String = "")
388387
@warn "Pkg.clone is only kept for legacy CI script reasons, please use `add`" maxlog=1
389-
add(joinpath(pkg...))
388+
ctx = Context()
389+
if !isempty(name)
390+
ctx.old_pkg2_clone_name = name
391+
end
392+
develop(ctx, [parse_package(url)])
390393
end
391394

392395
function dir(pkg::String, paths::String...)

stdlib/Pkg3/src/Types.jl

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,8 @@ Base.@kwdef mutable struct Context
569569
num_concurrent_downloads::Int = 8
570570
graph_verbose::Bool = false
571571
stdlibs::Dict{UUID,String} = gather_stdlib_uuids()
572+
# Remove next field when support for Pkg2 CI scripts is removed
573+
old_pkg2_clone_name::String = ""
572574
end
573575

574576
function Context!(ctx::Context; kwargs...)
@@ -652,7 +654,7 @@ function handle_repos_develop!(ctx::Context, pkgs::AbstractVector{PackageSpec})
652654
pkg.path = abspath(pkg.repo.url)
653655
folder_already_downloaded = true
654656
project_path = pkg.repo.url
655-
parse_package!(env, pkg, project_path)
657+
parse_package!(ctx, pkg, project_path)
656658
else
657659
# We save the repo in case another environement wants to
658660
# develop from the same repo, this avoids having to reclone it
@@ -675,11 +677,17 @@ function handle_repos_develop!(ctx::Context, pkgs::AbstractVector{PackageSpec})
675677
cp(repo_path, project_path; force=true)
676678
repo = LibGit2.GitRepo(project_path)
677679
rev = pkg.repo.rev
678-
isempty(rev) && (rev = LibGit2.branch(repo))
680+
if isempty(rev)
681+
if LibGit2.isattached(repo)
682+
rev = LibGit2.branch(repo)
683+
else
684+
rev = string(LibGit2.GitHash(LibGit2.head(repo)))
685+
end
686+
end
679687
gitobject, isbranch = checkout_rev!(repo, rev)
680688
close(repo); close(gitobject)
681689

682-
parse_package!(env, pkg, project_path)
690+
parse_package!(ctx, pkg, project_path)
683691
dev_pkg_path = joinpath(Pkg3.devdir(), pkg.name)
684692
if isdir(dev_pkg_path)
685693
if !isfile(joinpath(dev_pkg_path, "src", pkg.name * ".jl"))
@@ -735,7 +743,13 @@ function handle_repos_add!(ctx::Context, pkgs::AbstractVector{PackageSpec}; upgr
735743
end
736744

737745
# see if we can get rev as a branch
738-
isempty(rev) && (rev = LibGit2.branch(repo); pkg.repo.rev = rev)
746+
if isempty(rev)
747+
if LibGit2.isattached(repo)
748+
rev = LibGit2.branch(repo)
749+
else
750+
rev = string(LibGit2.GitHash(LibGit2.head(repo)))
751+
end
752+
end
739753
gitobject, isbranch = checkout_rev!(repo, rev)
740754
if !isbranch
741755
# 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
765779
LibGit2.checkout_tree(repo, git_tree, options=opts)
766780
end
767781
close(repo); close(git_tree); close(gitobject)
768-
parse_package!(env, pkg, project_path)
782+
parse_package!(ctx, pkg, project_path)
769783
if !folder_already_downloaded
770784
version_path = Pkg3.Operations.find_installed(pkg.name, pkg.uuid, pkg.repo.git_tree_sha1)
771785
mkpath(version_path)
@@ -777,7 +791,8 @@ function handle_repos_add!(ctx::Context, pkgs::AbstractVector{PackageSpec}; upgr
777791
return new_uuids
778792
end
779793

780-
function parse_package!(env, pkg, project_path)
794+
function parse_package!(ctx, pkg, project_path)
795+
env = ctx.env
781796
found_project_file = false
782797
for projname in project_names
783798
if isfile(joinpath(project_path, projname))
@@ -796,10 +811,14 @@ function parse_package!(env, pkg, project_path)
796811
end
797812
if !found_project_file
798813
@warn "packages will require to have a [Julia]Project.toml file in the future"
799-
# This is an old style package, get the name from the url.
800-
m = match(reg_pkg, pkg.repo.url)
801-
m === nothing && cmderror("cannot determine package name from URL: $(pkg.repo.url)")
802-
pkg.name = m.captures[1]
814+
if !isempty(ctx.old_pkg2_clone_name) # remove when legacy CI script support is removed
815+
pkg.name = ctx.old_pkg2_clone_name
816+
else
817+
# This is an old style package, get the name from src/PackageName
818+
m = match(reg_pkg, pkg.repo.url)
819+
m === nothing && cmderror("cannot determine package name from URL: $(pkg.repo.url)")
820+
pkg.name = m.captures[1]
821+
end
803822
reg_uuids = registered_uuids(env, pkg.name)
804823
is_registered = !isempty(reg_uuids)
805824
if !is_registered

0 commit comments

Comments
 (0)