Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show methods for Signatures and Commits #19951

Merged
merged 1 commit into from
Jan 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions base/libgit2/commit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ function committer(c::GitCommit)
return Signature(ptr)
end

function Base.show(io::IO, c::GitCommit)
authstr = sprint(show, author(c))
cmtrstr = sprint(show, committer(c))
print(io, "Git Commit:\nCommit Author: $authstr\nCommitter: $cmtrstr\nSHA: $(GitHash(c))\nMessage:\n$(message(c))")
end

""" Wrapper around `git_commit_create` """
function commit(repo::GitRepo,
refname::AbstractString,
Expand Down
2 changes: 2 additions & 0 deletions base/libgit2/signature.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ function Base.convert(::Type{GitSignature}, sig::Signature)
return GitSignature(sig_ptr_ptr[])
end

Base.show(io::IO, sig::Signature) = print(io, "Name: $(sig.name), Email: $(sig.email), Time: $(Dates.unix2datetime(sig.time + sig.time_offset))")

"""Return signature object. Free it after use."""
function default_signature(repo::GitRepo)
sig_ptr_ptr = Ref{Ptr{SignatureStruct}}(C_NULL)
Expand Down
8 changes: 8 additions & 0 deletions test/libgit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,14 @@ mktempdir() do dir
@test cmtr.time == test_sig.time
@test cmtr.email == test_sig.email
@test LibGit2.message(cmt) == commit_msg1
showstr = split(sprint(show, cmt), "\n")
# the time of the commit will vary so just test the first two parts
@test contains(showstr[1], "Git Commit:")
@test contains(showstr[2], "Commit Author: Name: TEST, Email: TEST@TEST.COM, Time:")
@test contains(showstr[3], "Committer: Name: TEST, Email: TEST@TEST.COM, Time:")
@test contains(showstr[4], "SHA:")
@test showstr[5] == "Message:"
@test showstr[6] == commit_msg1
finally
close(cmt)
end
Expand Down