Skip to content

Commit 589b399

Browse files
authored
Merge pull request #20834 from JuliaLang/ksh/showrebase
Add show methods for GitRebase and RebaseOperation
2 parents fce3014 + 8ca9f4c commit 589b399

File tree

4 files changed

+42
-8
lines changed

4 files changed

+42
-8
lines changed

base/libgit2/consts.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,12 @@ module Consts
177177
const RESET_HARD = Cint(3) # MIXED plus changes in working tree discarded
178178

179179
#rebase
180-
const REBASE_OPERATION_PICK = Cint(0)
181-
const REBASE_OPERATION_REWORD = Cint(1)
182-
const REBASE_OPERATION_EDIT = Cint(2)
183-
const REBASE_OPERATION_SQUASH = Cint(3)
184-
const REBASE_OPERATION_FIXUP = Cint(4)
185-
const REBASE_OPERATION_EXEC = Cint(5)
180+
@enum(GIT_REBASE_OPERATION, REBASE_OPERATION_PICK = Cint(0),
181+
REBASE_OPERATION_REWORD = Cint(1),
182+
REBASE_OPERATION_EDIT = Cint(2),
183+
REBASE_OPERATION_SQUASH = Cint(3),
184+
REBASE_OPERATION_FIXUP = Cint(4),
185+
REBASE_OPERATION_EXEC = Cint(5))
186186

187187
# fetch_prune
188188
const FETCH_PRUNE_UNSPECIFIED = Cint(0)

base/libgit2/rebase.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ function current(rb::GitRebase)
2121
end
2222

2323
function Base.getindex(rb::GitRebase, i::Integer)
24+
if !(1 <= i <= count(rb))
25+
throw(BoundsError(rb, (i,)))
26+
end
2427
rb_op_ptr = ccall((:git_rebase_operation_byindex, :libgit2),
2528
Ptr{RebaseOperation},
2629
(Ptr{Void}, Csize_t), rb.ptr, i-1)
27-
rb_op_ptr == C_NULL && return nothing
2830
return unsafe_load(rb_op_ptr)
2931
end
3032

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

46+
function Base.show(io::IO, rb::GitRebase)
47+
println(io, "GitRebase:")
48+
println(io, "Number: ", count(rb))
49+
println(io, "Currently performing operation: ",current(rb)+1)
50+
end
4451

4552
"""
4653
LibGit2.commit(rb::GitRebase, sig::GitSignature)

base/libgit2/types.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,10 @@ struct RebaseOperation
419419
id::GitHash
420420
exec::Cstring
421421
end
422-
Base.show(io::IO, rbo::RebaseOperation) = print(io, "RebaseOperation($(string(rbo.id)))")
422+
function Base.show(io::IO, rbo::RebaseOperation)
423+
println(io, "RebaseOperation($(string(rbo.id)))")
424+
println(io, "Operation type: $(Consts.GIT_REBASE_OPERATION(rbo.optype))")
425+
end
423426

424427
"""
425428
LibGit2.StatusOptions

test/libgit2.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,30 @@ mktempdir() do dir
842842

843843
newerhead = LibGit2.head_oid(repo)
844844
@test newerhead == newhead
845+
846+
# add yet more files
847+
open(joinpath(LibGit2.path(repo),"file5"),"w") do f
848+
write(f, "555\n")
849+
end
850+
LibGit2.add!(repo, "file5")
851+
LibGit2.commit(repo, "add file5")
852+
open(joinpath(LibGit2.path(repo),"file6"),"w") do f
853+
write(f, "666\n")
854+
end
855+
LibGit2.add!(repo, "file6")
856+
LibGit2.commit(repo, "add file6")
857+
858+
# Rebase type
859+
head_ann = LibGit2.GitAnnotated(repo, "branch/a")
860+
upst_ann = LibGit2.GitAnnotated(repo, "master")
861+
rb = LibGit2.GitRebase(repo, head_ann, upst_ann)
862+
@test_throws BoundsError rb[3]
863+
@test_throws BoundsError rb[0]
864+
rbo = next(rb)
865+
rbo_str = sprint(show, rbo)
866+
@test rbo_str == "RebaseOperation($(string(rbo.id)))\nOperation type: REBASE_OPERATION_PICK\n"
867+
rb_str = sprint(show, rb)
868+
@test rb_str == "GitRebase:\nNumber: 2\nCurrently performing operation: 1\n"
845869
finally
846870
close(repo)
847871
end

0 commit comments

Comments
 (0)