Skip to content

Commit 07147a8

Browse files
authored
Support git_repository_message, git_repository_message_remove (#734)
Closes #646
1 parent 4b2ac7c commit 07147a8

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

merge_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ func TestMergeWithSelf(t *testing.T) {
4343
mergeHeads[0] = mergeHead
4444
err = repo.Merge(mergeHeads, nil, nil)
4545
checkFatal(t, err)
46+
47+
mergeMessage, err := repo.Message()
48+
checkFatal(t, err)
49+
50+
expectedMessage := "Merge branch 'master'\n"
51+
if mergeMessage != expectedMessage {
52+
t.Errorf("merge Message = %v, want %v", mergeMessage, expectedMessage)
53+
}
4654
}
4755

4856
func TestMergeAnalysisWithSelf(t *testing.T) {

repository.go

+36
Original file line numberDiff line numberDiff line change
@@ -688,3 +688,39 @@ func (r *Repository) ClearGitIgnoreRules() error {
688688
}
689689
return nil
690690
}
691+
692+
// Message retrieves git's prepared message.
693+
// Operations such as git revert/cherry-pick/merge with the -n option stop just
694+
// short of creating a commit with the changes and save their prepared message
695+
// in .git/MERGE_MSG so the next git-commit execution can present it to the
696+
// user for them to amend if they wish.
697+
//
698+
// Use this function to get the contents of this file. Don't forget to remove
699+
// the file after you create the commit.
700+
func (r *Repository) Message() (string, error) {
701+
buf := C.git_buf{}
702+
defer C.git_buf_dispose(&buf)
703+
704+
runtime.LockOSThread()
705+
defer runtime.UnlockOSThread()
706+
707+
cErr := C.git_repository_message(&buf, r.ptr)
708+
runtime.KeepAlive(r)
709+
if cErr < 0 {
710+
return "", MakeGitError(cErr)
711+
}
712+
return C.GoString(buf.ptr), nil
713+
}
714+
715+
// RemoveMessage removes git's prepared message.
716+
func (r *Repository) RemoveMessage() error {
717+
runtime.LockOSThread()
718+
defer runtime.UnlockOSThread()
719+
720+
cErr := C.git_repository_message_remove(r.ptr)
721+
runtime.KeepAlive(r)
722+
if cErr < 0 {
723+
return MakeGitError(cErr)
724+
}
725+
return nil
726+
}

0 commit comments

Comments
 (0)