summaryrefslogtreecommitdiff
path: root/repository.go
diff options
context:
space:
mode:
authorByoungchan Lee <[email protected]>2021-02-03 12:42:21 +0900
committerGitHub <[email protected]>2021-02-02 19:42:21 -0800
commit07147a8ea8ccf216fa490e7ed4ec84e7c5f5d9ee (patch)
tree100c2994b9f65ec4fbd7fa9a2d44c8156c6b5b22 /repository.go
parent4b2ac7c998be677d865367908787f17fb570c679 (diff)
Support git_repository_message, git_repository_message_remove (#734)
Closes #646
Diffstat (limited to 'repository.go')
-rw-r--r--repository.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/repository.go b/repository.go
index d2b9961..bba5700 100644
--- a/repository.go
+++ b/repository.go
@@ -688,3 +688,39 @@ func (r *Repository) ClearGitIgnoreRules() error {
}
return nil
}
+
+// Message retrieves git's prepared message.
+// Operations such as git revert/cherry-pick/merge with the -n option stop just
+// short of creating a commit with the changes and save their prepared message
+// in .git/MERGE_MSG so the next git-commit execution can present it to the
+// user for them to amend if they wish.
+//
+// Use this function to get the contents of this file. Don't forget to remove
+// the file after you create the commit.
+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
+}
+
+// RemoveMessage removes git's prepared message.
+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
+}