MCPcopy Create free account
hub / github.com/libgit2/git2go / CreateCommit

Method CreateCommit

repository.go:432–489  ·  view source on GitHub ↗
(
	refname string, author, committer *Signature,
	message string, tree *Tree, parents ...*Commit)

Source from the content-addressed store, hash-verified

430}
431
432func (v *Repository) CreateCommit(
433 refname string, author, committer *Signature,
434 message string, tree *Tree, parents ...*Commit) (*Oid, error) {
435
436 oid := new(Oid)
437
438 var cref *C.char
439 if refname == "" {
440 cref = nil
441 } else {
442 cref = C.CString(refname)
443 defer C.free(unsafe.Pointer(cref))
444 }
445
446 cmsg := C.CString(message)
447 defer C.free(unsafe.Pointer(cmsg))
448
449 var cparents []*C.git_commit = nil
450 var parentsarg **C.git_commit = nil
451
452 nparents := len(parents)
453 if nparents > 0 {
454 cparents = make([]*C.git_commit, nparents)
455 for i, v := range parents {
456 cparents[i] = v.cast_ptr
457 }
458 parentsarg = &cparents[0]
459 }
460
461 authorSig, err := author.toC()
462 if err != nil {
463 return nil, err
464 }
465 defer C.git_signature_free(authorSig)
466
467 committerSig, err := committer.toC()
468 if err != nil {
469 return nil, err
470 }
471 defer C.git_signature_free(committerSig)
472
473 runtime.LockOSThread()
474 defer runtime.UnlockOSThread()
475
476 ret := C.git_commit_create(
477 oid.toC(), v.ptr, cref,
478 authorSig, committerSig,
479 nil, cmsg, tree.cast_ptr, C.size_t(nparents), parentsarg)
480
481 runtime.KeepAlive(v)
482 runtime.KeepAlive(oid)
483 runtime.KeepAlive(parents)
484 if ret < 0 {
485 return nil, MakeGitError(ret)
486 }
487
488 return oid, nil
489}

Callers 10

TestCreateCommitFromIdsFunction · 0.80
TestRepositorySetConfigFunction · 0.80
commitSomethingFunction · 0.80
prepareStashRepoFunction · 0.80
seedTestRepoOptFunction · 0.80
updateReadmeFunction · 0.80
TestApplyDiffAddfileFunction · 0.80
addAndGetTreeFunction · 0.80
TestReferenceIteratorFunction · 0.80
appendCommitFunction · 0.80

Calls 3

MakeGitErrorFunction · 0.85
freeMethod · 0.80
toCMethod · 0.45

Tested by 10

TestCreateCommitFromIdsFunction · 0.64
TestRepositorySetConfigFunction · 0.64
commitSomethingFunction · 0.64
prepareStashRepoFunction · 0.64
seedTestRepoOptFunction · 0.64
updateReadmeFunction · 0.64
TestApplyDiffAddfileFunction · 0.64
addAndGetTreeFunction · 0.64
TestReferenceIteratorFunction · 0.64
appendCommitFunction · 0.64