Skip to content

Commit

Permalink
Merge pull request #20834 from JuliaLang/ksh/showrebase
Browse files Browse the repository at this point in the history
Add show methods for GitRebase and RebaseOperation
  • Loading branch information
kshyatt committed Mar 3, 2017
2 parents fce3014 + 8ca9f4c commit 589b399
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
12 changes: 6 additions & 6 deletions base/libgit2/consts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ module Consts
const RESET_HARD = Cint(3) # MIXED plus changes in working tree discarded

#rebase
const REBASE_OPERATION_PICK = Cint(0)
const REBASE_OPERATION_REWORD = Cint(1)
const REBASE_OPERATION_EDIT = Cint(2)
const REBASE_OPERATION_SQUASH = Cint(3)
const REBASE_OPERATION_FIXUP = Cint(4)
const REBASE_OPERATION_EXEC = Cint(5)
@enum(GIT_REBASE_OPERATION, REBASE_OPERATION_PICK = Cint(0),
REBASE_OPERATION_REWORD = Cint(1),
REBASE_OPERATION_EDIT = Cint(2),
REBASE_OPERATION_SQUASH = Cint(3),
REBASE_OPERATION_FIXUP = Cint(4),
REBASE_OPERATION_EXEC = Cint(5))

# fetch_prune
const FETCH_PRUNE_UNSPECIFIED = Cint(0)
Expand Down
9 changes: 8 additions & 1 deletion base/libgit2/rebase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ function current(rb::GitRebase)
end

function Base.getindex(rb::GitRebase, i::Integer)
if !(1 <= i <= count(rb))
throw(BoundsError(rb, (i,)))
end
rb_op_ptr = ccall((:git_rebase_operation_byindex, :libgit2),
Ptr{RebaseOperation},
(Ptr{Void}, Csize_t), rb.ptr, i-1)
rb_op_ptr == C_NULL && return nothing
return unsafe_load(rb_op_ptr)
end

Expand All @@ -41,6 +43,11 @@ function Base.next(rb::GitRebase)
return unsafe_load(rb_op_ptr_ptr[])
end

function Base.show(io::IO, rb::GitRebase)
println(io, "GitRebase:")
println(io, "Number: ", count(rb))
println(io, "Currently performing operation: ",current(rb)+1)
end

"""
LibGit2.commit(rb::GitRebase, sig::GitSignature)
Expand Down
5 changes: 4 additions & 1 deletion base/libgit2/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,10 @@ struct RebaseOperation
id::GitHash
exec::Cstring
end
Base.show(io::IO, rbo::RebaseOperation) = print(io, "RebaseOperation($(string(rbo.id)))")
function Base.show(io::IO, rbo::RebaseOperation)
println(io, "RebaseOperation($(string(rbo.id)))")
println(io, "Operation type: $(Consts.GIT_REBASE_OPERATION(rbo.optype))")
end

"""
LibGit2.StatusOptions
Expand Down
24 changes: 24 additions & 0 deletions test/libgit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,30 @@ mktempdir() do dir

newerhead = LibGit2.head_oid(repo)
@test newerhead == newhead

# add yet more files
open(joinpath(LibGit2.path(repo),"file5"),"w") do f
write(f, "555\n")
end
LibGit2.add!(repo, "file5")
LibGit2.commit(repo, "add file5")
open(joinpath(LibGit2.path(repo),"file6"),"w") do f
write(f, "666\n")
end
LibGit2.add!(repo, "file6")
LibGit2.commit(repo, "add file6")

# Rebase type
head_ann = LibGit2.GitAnnotated(repo, "branch/a")
upst_ann = LibGit2.GitAnnotated(repo, "master")
rb = LibGit2.GitRebase(repo, head_ann, upst_ann)
@test_throws BoundsError rb[3]
@test_throws BoundsError rb[0]
rbo = next(rb)
rbo_str = sprint(show, rbo)
@test rbo_str == "RebaseOperation($(string(rbo.id)))\nOperation type: REBASE_OPERATION_PICK\n"
rb_str = sprint(show, rb)
@test rb_str == "GitRebase:\nNumber: 2\nCurrently performing operation: 1\n"
finally
close(repo)
end
Expand Down

0 comments on commit 589b399

Please sign in to comment.