Skip to content

Add support for git_blob_is_binary #625

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

Merged
merged 2 commits into from
Jul 30, 2020
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
6 changes: 6 additions & 0 deletions blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
20 changes: 19 additions & 1 deletion blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
}
}
}