Skip to content

Commit

Permalink
work around strange "Unreachable reached" when the close function for…
Browse files Browse the repository at this point in the history
… the repo fires

(cherry picked from commit 90ca61b)
  • Loading branch information
KristofferC committed Sep 8, 2018
1 parent 7f88b2c commit 8f816db
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions stdlib/Pkg/src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ rm(pkgs::Vector{PackageSpec}; kwargs...) = rm(Context(), pkgs; kwargs...)

function rm(ctx::Context, pkgs::Vector{PackageSpec}; mode=PKGMODE_PROJECT, kwargs...)
for pkg in pkgs
#TODO only overwrite pkg.mode is default value ?
# TODO only overwrite pkg.mode if default value ?
pkg.mode = mode
end

Expand All @@ -98,39 +98,51 @@ function update_registry(ctx)
if isdir(joinpath(reg, ".git"))
regpath = pathrepr(reg)
printpkgstyle(ctx, :Updating, "registry at " * regpath)
LibGit2.with(LibGit2.GitRepo, reg) do repo
# Using LibGit2.with here crashes julia when running the
# tests for PkgDev wiht "Unreachable reached".
# This seems to work around it.
local repo
try
repo = LibGit2.GitRepo(reg)
if LibGit2.isdirty(repo)
push!(errors, (regpath, "registry dirty"))
return
@goto done
end
if !LibGit2.isattached(repo)
push!(errors, (regpath, "registry detached"))
return
@goto done
end
if !("origin" in LibGit2.remotes(repo))
push!(errors, (regpath, "origin not in the list of remotes"))
@goto done
end
branch = LibGit2.headname(repo)
try
GitTools.fetch(repo; refspecs=["+refs/heads/$branch:refs/remotes/origin/$branch"])
catch e
e isa PkgError || rethrow(e)
push!(errors, (reg, "failed to fetch from repo"))
return
@goto done
end
ff_succeeded = try
LibGit2.merge!(repo; branch="refs/remotes/origin/$branch", fastforward=true)
catch e
e isa LibGit2.GitError && e.code == LibGit2.Error.ENOTFOUND || rethrow(e)
push!(errors, (reg, "branch origin/$branch not found"))
return
@goto done
end

if !ff_succeeded
try LibGit2.rebase!(repo, "origin/$branch")
catch e
e isa LibGit2.GitError || rethrow(e)
push!(errors, (reg, "registry failed to rebase on origin/$branch"))
return
@goto done
end
end
@label done
finally
close(repo)
end
end
end
Expand Down

0 comments on commit 8f816db

Please sign in to comment.