Add support for git_blob_is_binary (#625)
This adds IsBinary() func to Blob struct, which simply returns the result of git_blob_is_binary function. Refs: https://libgit2.org/libgit2/#HEAD/group/blob/git_blob_is_binary Issue: Add support for git_blob_is_binary #426 Fixes: #426
This commit is contained in:
parent
d8f9990d4d
commit
462ebd83e0
6
blob.go
6
blob.go
|
@ -40,6 +40,12 @@ func (v *Blob) Contents() []byte {
|
|||
return goBytes
|
||||
}
|
||||
|
||||
func (v *Blob) IsBinary() bool {
|
||||
ret := C.git_blob_is_binary(v.cast_ptr) == 1
|
||||
runtime.KeepAlive(v)
|
||||
return ret
|
||||
}
|
||||
|
||||
func (repo *Repository) CreateBlobFromBuffer(data []byte) (*Oid, error) {
|
||||
runtime.LockOSThread()
|
||||
defer runtime.UnlockOSThread()
|
||||
|
|
20
blob_test.go
20
blob_test.go
|
@ -28,7 +28,21 @@ func TestCreateBlobFromBuffer(t *testing.T) {
|
|||
t.Fatal("Empty buffer did not deliver empty blob id")
|
||||
}
|
||||
|
||||
for _, data := range []([]byte){[]byte("hello there"), doublePointerBytes()} {
|
||||
tests := []struct {
|
||||
data []byte
|
||||
isBinary bool
|
||||
}{
|
||||
{
|
||||
data: []byte("hello there"),
|
||||
isBinary: false,
|
||||
},
|
||||
{
|
||||
data: doublePointerBytes(),
|
||||
isBinary: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
data := tt.data
|
||||
id, err = repo.CreateBlobFromBuffer(data)
|
||||
checkFatal(t, err)
|
||||
|
||||
|
@ -38,5 +52,9 @@ func TestCreateBlobFromBuffer(t *testing.T) {
|
|||
t.Fatal("Loaded bytes don't match original bytes:",
|
||||
blob.Contents(), "!=", data)
|
||||
}
|
||||
want := tt.isBinary
|
||||
if got := blob.IsBinary(); got != want {
|
||||
t.Fatalf("IsBinary() = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue