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

Add show methods for remotes and tags #19955

Merged
merged 1 commit into from
Jan 15, 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
10 changes: 9 additions & 1 deletion base/libgit2/remote.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it valid to have empty-name or empty-url remotes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can have Anonymous remotes, can't you?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that the only thing that can result in getting a null pointer back from this function?

return unsafe_string(name_ptr)
end

function fetch_refspecs(rmt::GitRemote)
Expand Down Expand Up @@ -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))
2 changes: 2 additions & 0 deletions base/libgit2/tag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kinda inconsistent to have one of these use interpolation and the other use multi-arg print

5 changes: 4 additions & 1 deletion test/libgit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down