From 8ee92375131824ef604a3f31e986cbfcff003e4f Mon Sep 17 00:00:00 2001 From: kshyatt Date: Mon, 9 Jan 2017 14:04:30 -0800 Subject: [PATCH] Add show methods for remotes and tags --- base/libgit2/remote.jl | 10 +++++++++- base/libgit2/tag.jl | 2 ++ test/libgit2.jl | 5 ++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/base/libgit2/remote.jl b/base/libgit2/remote.jl index 16a342405b1e3..16d9229520c86 100644 --- a/base/libgit2/remote.jl +++ b/base/libgit2/remote.jl @@ -35,7 +35,13 @@ end function url(rmt::GitRemote) url_ptr = ccall((:git_remote_url, :libgit2), Cstring, (Ptr{Void}, ), rmt.ptr) url_ptr == C_NULL && return "" - return unsafe_string(url_ptr) + return unsafe_string(url_ptr) +end + +function name(rmt::GitRemote) + name_ptr = ccall((:git_remote_name, :libgit2), Cstring, (Ptr{Void}, ), rmt.ptr) + name_ptr == C_NULL && return "" + return unsafe_string(name_ptr) end function fetch_refspecs(rmt::GitRemote) @@ -88,3 +94,5 @@ function push{T<:AbstractString}(rmt::GitRemote, refspecs::Vector{T}; !no_refs && close(sa) end end + +Base.show(io::IO, rmt::GitRemote) = print(io, "GitRemote:\nRemote name: ", name(rmt), " url: ", url(rmt)) diff --git a/base/libgit2/tag.jl b/base/libgit2/tag.jl index 728c23890ba50..f0565916c3dae 100644 --- a/base/libgit2/tag.jl +++ b/base/libgit2/tag.jl @@ -41,3 +41,5 @@ function target(tag::GitTag) oid_ptr == C_NULL && throw(Error.GitError(Error.ERROR)) return GitHash(oid_ptr) end + +Base.show(io::IO, tag::GitTag) = print(io, "GitTag:\nTag name: $(name(tag)) target: $(target(tag))") diff --git a/test/libgit2.jl b/test/libgit2.jl index 10082f1a78bb5..b1fc8900e62b1 100644 --- a/test/libgit2.jl +++ b/test/libgit2.jl @@ -180,6 +180,9 @@ mktempdir() do dir remote = LibGit2.get(LibGit2.GitRemote, repo, branch) @test LibGit2.url(remote) == repo_url + @test LibGit2.name(remote) == "upstream" + @test isa(remote, LibGit2.GitRemote) + @test sprint(show, remote) == "GitRemote:\nRemote name: upstream url: $repo_url" @test LibGit2.isattached(repo) close(remote) finally @@ -394,7 +397,7 @@ mktempdir() do dir tag1tag = LibGit2.peel(LibGit2.GitTag,tag1ref) @test LibGit2.name(tag1tag) == tag1 @test LibGit2.target(tag1tag) == commit_oid1 - + @test sprint(show, tag1tag) == "GitTag:\nTag name: $tag1 target: $commit_oid1" tag_oid2 = LibGit2.tag_create(repo, tag2, commit_oid2) @test !LibGit2.iszero(tag_oid2) tags = LibGit2.tag_list(repo)