Skip to content

Commit

Permalink
update registries when adding (#253)
Browse files Browse the repository at this point in the history
* update registries when adding

* done error out if we fail to fetch repo
  • Loading branch information
KristofferC committed Apr 19, 2018
1 parent 0a3a9ee commit 78d4ed1
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions stdlib/Pkg3/src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function add_or_develop(ctx::Context, pkgs::Vector{PackageSpec}; mode::Symbol, k
new_git = handle_repos_develop!(ctx, pkgs)
else
new_git = handle_repos_add!(ctx, pkgs; upgrade_or_add=true)
update_registry(ctx)
end
project_deps_resolve!(ctx.env, pkgs)
registry_resolve!(ctx.env, pkgs)
Expand Down Expand Up @@ -56,17 +57,7 @@ function rm(ctx::Context, pkgs::Vector{PackageSpec}; kwargs...)
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...)

function up(ctx::Context, pkgs::Vector{PackageSpec};
level::UpgradeLevel=UPLEVEL_MAJOR, mode::PackageMode=PKGMODE_PROJECT, kwargs...)
print_first_command_header()
Context!(ctx; kwargs...)
ctx.preview && preview_info()

function update_registry(ctx)
# Update the registry
errors = Tuple{String, String}[]
if ctx.preview
Expand All @@ -86,7 +77,13 @@ function up(ctx::Context, pkgs::Vector{PackageSpec};
return
end
branch = LibGit2.headname(repo)
GitTools.fetch(repo)
try
GitTools.fetch(repo)
catch e
e isa LibGit2.GitError || rethrow(e)
push!(errors, (reg, "failed to fetch from repo"))
return
end
ff_succeeded = try
LibGit2.merge!(repo; branch="refs/remotes/origin/$branch", fastforward=true)
catch e
Expand All @@ -107,15 +104,26 @@ function up(ctx::Context, pkgs::Vector{PackageSpec};
end
end
end

if !isempty(errors)
warn_str = "Some registries failed to update:"
for (reg, err) in errors
warn_str *= "\n$reg$err"
end
@warn warn_str
end
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...)

function up(ctx::Context, pkgs::Vector{PackageSpec};
level::UpgradeLevel=UPLEVEL_MAJOR, mode::PackageMode=PKGMODE_PROJECT, kwargs...)
print_first_command_header()
Context!(ctx; kwargs...)
ctx.preview && preview_info()
update_registry(ctx)
if isempty(pkgs)
if mode == PKGMODE_PROJECT
for (name::String, uuidstr::String) in ctx.env.project["deps"]
Expand Down

0 comments on commit 78d4ed1

Please sign in to comment.