Skip to content

Commit

Permalink
fix bug when cloned package does not have HEAD ref
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebolewski committed Nov 3, 2015
1 parent 99dc2eb commit 1b7c4a2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
6 changes: 4 additions & 2 deletions base/libgit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ include("libgit2/status.jl")
include("libgit2/tree.jl")
include("libgit2/callbacks.jl")

using .Error

immutable State
head::Oid
index::Oid
Expand Down Expand Up @@ -371,7 +373,7 @@ function merge!(repo::GitRepo;
fheads = fetchheads(repo)
filter!(fh->fh.ismerge, fheads)
if isempty(fheads)
throw(Error.GitError(Error.Merge,Error.ERROR,
throw(GitError(Error.Merge, Error.ERROR,
"There is no fetch reference for this branch."))
end
map(fh->GitAnnotated(repo,fh), fheads)
Expand All @@ -385,7 +387,7 @@ function merge!(repo::GitRepo;
end
else # try to get tracking remote branch for the head
if !isattached(repo)
throw(Error.GitError(Error.Merge, Error.ERROR,
throw(GitError(Error.Merge, Error.ERROR,
"There is no tracking information for the current branch."))
end
with(upstream(head_ref)) do tr_brn_ref
Expand Down
2 changes: 2 additions & 0 deletions base/libgit2/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module Error

export GitError

@enum(Code, GIT_OK = Cint(0), # no error
ERROR = Cint(-01), # generic error
ENOTFOUND = Cint(-03), # requested object could not be found
Expand Down
2 changes: 0 additions & 2 deletions base/libgit2/index.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ function Base.count(idx::GitIndex)
end

function Base.getindex(idx::GitIndex, i::Csize_t)
# return ccall((:git_index_get_byindex, :libgit2), Ptr{Void},
# (Ptr{Void}, Csize_t), idx.ptr, i)
ie_ptr = ccall((:git_index_get_byindex, :libgit2), Ptr{Void},
(Ptr{Void}, Csize_t), idx.ptr, i-1)
ie_ptr == C_NULL && return nothing
Expand Down
13 changes: 12 additions & 1 deletion base/pkg/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,18 @@ function installed_version(pkg::AbstractString, prepo::LibGit2.GitRepo, avail::D
ispath(pkg,".git") || return typemin(VersionNumber)

# get package repo head hash
head = string(LibGit2.head_oid(prepo))
local head
try
head = string(LibGit2.head_oid(prepo))
catch ex
# refs/heads/master does not exist
if isa(ex,LibGit2.GitError) &&
ex.code == LibGit2.Error.EUNBORNBRANCH
head = ""
else
rethrow(ex)
end
end
isempty(head) && return typemin(VersionNumber)

vers = collect(keys(filter((ver,info)->info.sha1==head, avail)))
Expand Down

0 comments on commit 1b7c4a2

Please sign in to comment.