From 99c53051667407f482c6e5bbcc773ecb49d1c786 Mon Sep 17 00:00:00 2001 From: Byoungchan Lee Date: Mon, 1 Feb 2021 22:16:22 +0900 Subject: [PATCH] Support git_repository_message, git_repository_message_remove --- merge_test.go | 8 ++++++++ repository.go | 27 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/merge_test.go b/merge_test.go index d49d07c..981f672 100644 --- a/merge_test.go +++ b/merge_test.go @@ -43,6 +43,14 @@ func TestMergeWithSelf(t *testing.T) { mergeHeads[0] = mergeHead err = repo.Merge(mergeHeads, nil, nil) checkFatal(t, err) + + mergeMessage, err := repo.Message() + checkFatal(t, err) + + expectedMessage := "Merge branch 'master'\n" + if mergeMessage != expectedMessage { + t.Errorf("mege Meesage = %v, want %v", mergeMessage, expectedMessage) + } } func TestMergeAnalysisWithSelf(t *testing.T) { diff --git a/repository.go b/repository.go index d2b9961..b0ea84c 100644 --- a/repository.go +++ b/repository.go @@ -688,3 +688,30 @@ func (r *Repository) ClearGitIgnoreRules() error { } return nil } + +func (r *Repository) Message() (string, error) { + buf := C.git_buf{} + defer C.git_buf_dispose(&buf) + + runtime.LockOSThread() + defer runtime.UnlockOSThread() + + cErr := C.git_repository_message(&buf, r.ptr) + runtime.KeepAlive(r) + if cErr < 0 { + return "", MakeGitError(cErr) + } + return C.GoString(buf.ptr), nil +} + +func (r *Repository) RemoveMessage() error { + runtime.LockOSThread() + defer runtime.UnlockOSThread() + + cErr := C.git_repository_message_remove(r.ptr) + runtime.KeepAlive(r) + if cErr < 0 { + return MakeGitError(cErr) + } + return nil +}