From e1378949b822648b78cfba7708364adfc55355ec Mon Sep 17 00:00:00 2001 From: Katie Hyatt Date: Thu, 2 Jun 2016 14:06:49 -0700 Subject: [PATCH 1/4] Fixed `target` for `GitTag` and added more tests. --- base/libgit2/tag.jl | 5 +++-- test/libgit2.jl | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/base/libgit2/tag.jl b/base/libgit2/tag.jl index 83b822ea85a2f..abb29529d9a88 100644 --- a/base/libgit2/tag.jl +++ b/base/libgit2/tag.jl @@ -35,6 +35,7 @@ function name(tag::GitTag) end function target(tag::GitTag) - oid_ptr = Ref(ccall((:git_tag_target_id, :libgit2), Ptr{Oid}, (Ptr{Void}, ), tag.ptr)) - return oid_ptr[] + oid_ptr = ccall((:git_tag_target_id, :libgit2), Ptr{Oid}, (Ptr{Void}, ), tag.ptr) + oid_ptr == C_NULL && return Oid() + return Oid(oid_ptr) end diff --git a/test/libgit2.jl b/test/libgit2.jl index d36ede39426fd..bcd8b59e49825 100644 --- a/test/libgit2.jl +++ b/test/libgit2.jl @@ -315,6 +315,10 @@ mktempdir() do dir tags = LibGit2.tag_list(repo) @test length(tags) == 1 @test tag1 in tags + tag1ref = LibGit2.GitReference(repo, "refs/tags/$tag1") + tag1tag = LibGit2.peel(LibGit2.GitTag,tag1ref) + @test LibGit2.name(tag1tag) == tag1 + @test LibGit2.target(tag1tag) == commit_oid1 tag_oid2 = LibGit2.tag_create(repo, tag2, commit_oid2) @test !LibGit2.iszero(tag_oid2) From e49377d6fd45ddb95cb601f93cb509d9295eaadf Mon Sep 17 00:00:00 2001 From: Katie Hyatt Date: Thu, 2 Jun 2016 14:07:06 -0700 Subject: [PATCH 2/4] Added functoin to list all git references and added test. --- base/libgit2/reference.jl | 16 ++++++++++++++++ test/libgit2.jl | 3 +++ 2 files changed, 19 insertions(+) diff --git a/base/libgit2/reference.jl b/base/libgit2/reference.jl index 444704bef6780..47c35efe64a1b 100644 --- a/base/libgit2/reference.jl +++ b/base/libgit2/reference.jl @@ -73,6 +73,13 @@ function isbranch(ref::GitReference) return err == 1 end +function istag(ref::GitReference) + isempty(ref) && return false + err = ccall((:git_reference_is_tag, :libgit2), Cint, + (Ptr{Void},), ref.ptr) + return err == 1 +end + function isremote(ref::GitReference) isempty(ref) && return false err = ccall((:git_reference_is_remote, :libgit2), Cint, @@ -96,6 +103,15 @@ function peel{T <: GitObject}(::Type{T}, ref::GitReference) return T(obj_ptr_ptr[]) end +function ref_list(repo::GitRepo) + with(StrArrayStruct()) do sa + sa_ref = Ref(sa) + @check ccall((:git_reference_list, :libgit2), Cint, + (Ptr{StrArrayStruct}, Ptr{Void}), sa_ref, repo.ptr) + convert(Vector{AbstractString}, sa_ref[]) + end +end + function create_branch(repo::GitRepo, bname::AbstractString, commit_obj::GitCommit; diff --git a/test/libgit2.jl b/test/libgit2.jl index bcd8b59e49825..96f2c778f4d4f 100644 --- a/test/libgit2.jl +++ b/test/libgit2.jl @@ -326,6 +326,9 @@ mktempdir() do dir @test length(tags) == 2 @test tag2 in tags + refs = LibGit2.ref_list(repo) + @test refs == ["refs/heads/master","refs/heads/test_branch","refs/tags/tag1","refs/tags/tag2"] + LibGit2.tag_delete(repo, tag1) tags = LibGit2.tag_list(repo) @test length(tags) == 1 From 4761fc6757a8ce5b5d8a049737ca7bc2a0293976 Mon Sep 17 00:00:00 2001 From: Katie Hyatt Date: Thu, 2 Jun 2016 20:59:10 -0700 Subject: [PATCH 3/4] Add test for `fullname` and `authors` --- test/libgit2.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/libgit2.jl b/test/libgit2.jl index 96f2c778f4d4f..a446d592fc7c7 100644 --- a/test/libgit2.jl +++ b/test/libgit2.jl @@ -219,6 +219,13 @@ mktempdir() do dir @test LibGit2.iszero(commit_oid2) commit_oid2 = LibGit2.commit(repo, commit_msg2; author=test_sig, committer=test_sig) @test !LibGit2.iszero(commit_oid2) + auths = LibGit2.authors(repo) + @test length(auths) == 3 + for auth in auths + @test auth.name == test_sig.name + @test auth.time == test_sig.time + @test auth.email == test_sig.email + end # lookup commits cmt = LibGit2.get(LibGit2.GitCommit, repo, commit_oid1) @@ -316,6 +323,7 @@ mktempdir() do dir @test length(tags) == 1 @test tag1 in tags tag1ref = LibGit2.GitReference(repo, "refs/tags/$tag1") + @test isempty(LibGit2.fullname(tag1ref)) #because this is a reference to an OID tag1tag = LibGit2.peel(LibGit2.GitTag,tag1ref) @test LibGit2.name(tag1tag) == tag1 @test LibGit2.target(tag1tag) == commit_oid1 From 78cf30be887a163b714aaa20afbb4ca3033ced44 Mon Sep 17 00:00:00 2001 From: Katie Hyatt Date: Mon, 6 Jun 2016 14:38:43 -0700 Subject: [PATCH 4/4] Added error throw --- base/libgit2/tag.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/base/libgit2/tag.jl b/base/libgit2/tag.jl index abb29529d9a88..71f40b3a494c5 100644 --- a/base/libgit2/tag.jl +++ b/base/libgit2/tag.jl @@ -31,11 +31,13 @@ function tag_create(repo::GitRepo, tag::AbstractString, commit::Union{AbstractSt end function name(tag::GitTag) - return String(ccall((:git_tag_name, :libgit2), Cstring, (Ptr{Void}, ), tag.ptr)) + str_ptr = ccall((:git_tag_name, :libgit2), Cstring, (Ptr{Void}, ), tag.ptr) + str_ptr == C_NULL && throw(Error.GitError(Error.ERROR)) + return String(str_ptr) end function target(tag::GitTag) oid_ptr = ccall((:git_tag_target_id, :libgit2), Ptr{Oid}, (Ptr{Void}, ), tag.ptr) - oid_ptr == C_NULL && return Oid() + oid_ptr == C_NULL && throw(Error.GitError(Error.ERROR)) return Oid(oid_ptr) end