diff --git a/base/libgit2/diff.jl b/base/libgit2/diff.jl index d515b8a223b1b..3b1f1d3df5793 100644 --- a/base/libgit2/diff.jl +++ b/base/libgit2/diff.jl @@ -36,9 +36,12 @@ function Base.count(diff::GitDiff) end function Base.getindex(diff::GitDiff, i::Csize_t) + if i < 1 || i >= count(diff) + throw(BoundsError()) + end delta_ptr = ccall((:git_diff_get_delta, :libgit2), Ptr{Void}, (Ptr{Void}, Csize_t), diff.ptr, i-1) - delta_ptr == C_NULL && return nothing + delta_ptr == C_NULL && throw(Error.GitError(Error.ERROR)) return unsafe_load(convert(Ptr{DiffDelta}, delta_ptr), 1) end Base.getindex(diff::GitDiff, i::Int) = getindex(diff, Csize_t(i)) diff --git a/base/libgit2/index.jl b/base/libgit2/index.jl index c5af2191e7704..19f880035b19d 100644 --- a/base/libgit2/index.jl +++ b/base/libgit2/index.jl @@ -112,9 +112,12 @@ function Base.count(idx::GitIndex) end function Base.getindex(idx::GitIndex, i::Csize_t) + if i < 1 || i >= count(idx) + throw(BoundsError()) + end ie_ptr = ccall((:git_index_get_byindex, :libgit2), Ptr{Void}, (Ptr{Void}, Csize_t), idx.ptr, i-1) - ie_ptr == C_NULL && return nothing + ie_ptr == C_NULL && throw(Error.GitError(Error.ERROR)) return unsafe_load(convert(Ptr{IndexEntry}, ie_ptr), 1) end Base.getindex(idx::GitIndex, i::Int) = getindex(idx, Csize_t(i)) diff --git a/base/libgit2/rebase.jl b/base/libgit2/rebase.jl index 32c0da2d2a9af..3367f65d0cc46 100644 --- a/base/libgit2/rebase.jl +++ b/base/libgit2/rebase.jl @@ -21,9 +21,12 @@ function current(rb::GitRebase) end function Base.getindex(rb::GitRebase, i::Csize_t) + if i < 1 || i >= count(rb) + throw(BoundsError()) + end rb_op_ptr = ccall((:git_rebase_operation_byindex, :libgit2), Ptr{Void}, (Ptr{Void}, Csize_t), rb.ptr, i-1) - rb_op_ptr == C_NULL && return nothing + rb_op_ptr == C_NULL && throw(Error.GitError(Error.ERROR)) return unsafe_load(convert(Ptr{RebaseOperation}, rb_op_ptr), 1) end Base.getindex(rb::GitRebase, i::Int) = getindex(rb, Csize_t(i)) diff --git a/base/libgit2/tree.jl b/base/libgit2/tree.jl index 321bd83708d2c..0541896d55996 100644 --- a/base/libgit2/tree.jl +++ b/base/libgit2/tree.jl @@ -18,8 +18,8 @@ end function filename(te::GitTreeEntry) str = ccall((:git_tree_entry_name, :libgit2), Cstring, (Ptr{Void},), te.ptr) - str != C_NULL && return unsafe_string(str) - return nothing + str == C_NULL && throw(Error.GitError(Error.ERROR)) + return unsafe_string(str) end function filemode(te::GitTreeEntry) diff --git a/base/libgit2/walker.jl b/base/libgit2/walker.jl index 1d564c3c406db..b27cda5d8e5db 100644 --- a/base/libgit2/walker.jl +++ b/base/libgit2/walker.jl @@ -50,8 +50,8 @@ end function repository(w::GitRevWalker) ptr = ccall((:git_revwalk_repository, :libgit2), Ptr{Void}, (Ptr{Void},), w.ptr) - ptr != C_NULL && return GitRepo(ptr) - return nothing + ptr == C_NULL && throw(Error.GitError(Error.ERROR)) + return GitRepo(ptr) end function Base.map(f::Function, walker::GitRevWalker;