Skip to content

Commit 281e2be

Browse files
authored
Merge pull request #19955 from JuliaLang/ksh/showremoteandtag
Add show methods for remotes and tags
2 parents cf99703 + 8ee9237 commit 281e2be

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

base/libgit2/remote.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ end
3535
function url(rmt::GitRemote)
3636
url_ptr = ccall((:git_remote_url, :libgit2), Cstring, (Ptr{Void}, ), rmt.ptr)
3737
url_ptr == C_NULL && return ""
38-
return unsafe_string(url_ptr)
38+
return unsafe_string(url_ptr)
39+
end
40+
41+
function name(rmt::GitRemote)
42+
name_ptr = ccall((:git_remote_name, :libgit2), Cstring, (Ptr{Void}, ), rmt.ptr)
43+
name_ptr == C_NULL && return ""
44+
return unsafe_string(name_ptr)
3945
end
4046

4147
function fetch_refspecs(rmt::GitRemote)
@@ -88,3 +94,5 @@ function push{T<:AbstractString}(rmt::GitRemote, refspecs::Vector{T};
8894
!no_refs && close(sa)
8995
end
9096
end
97+
98+
Base.show(io::IO, rmt::GitRemote) = print(io, "GitRemote:\nRemote name: ", name(rmt), " url: ", url(rmt))

base/libgit2/tag.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,5 @@ function target(tag::GitTag)
4141
oid_ptr == C_NULL && throw(Error.GitError(Error.ERROR))
4242
return GitHash(oid_ptr)
4343
end
44+
45+
Base.show(io::IO, tag::GitTag) = print(io, "GitTag:\nTag name: $(name(tag)) target: $(target(tag))")

test/libgit2.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ mktempdir() do dir
180180

181181
remote = LibGit2.get(LibGit2.GitRemote, repo, branch)
182182
@test LibGit2.url(remote) == repo_url
183+
@test LibGit2.name(remote) == "upstream"
184+
@test isa(remote, LibGit2.GitRemote)
185+
@test sprint(show, remote) == "GitRemote:\nRemote name: upstream url: $repo_url"
183186
@test LibGit2.isattached(repo)
184187
close(remote)
185188
finally
@@ -394,7 +397,7 @@ mktempdir() do dir
394397
tag1tag = LibGit2.peel(LibGit2.GitTag,tag1ref)
395398
@test LibGit2.name(tag1tag) == tag1
396399
@test LibGit2.target(tag1tag) == commit_oid1
397-
400+
@test sprint(show, tag1tag) == "GitTag:\nTag name: $tag1 target: $commit_oid1"
398401
tag_oid2 = LibGit2.tag_create(repo, tag2, commit_oid2)
399402
@test !LibGit2.iszero(tag_oid2)
400403
tags = LibGit2.tag_list(repo)

0 commit comments

Comments
 (0)