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

Function addAndGetTree

diff_test.go:649–685  ·  view source on GitHub ↗

addAndGetTree creates a file and commits it, returning the commit and tree

(t *testing.T, repo *Repository, filename string, content string)

Source from the content-addressed store, hash-verified

647
648// addAndGetTree creates a file and commits it, returning the commit and tree
649func addAndGetTree(t *testing.T, repo *Repository, filename string, content string) (*Commit, *Tree) {
650 headCommit, err := headCommit(repo)
651 checkFatal(t, err)
652 defer headCommit.Free()
653
654 p := repo.Path()
655 p = strings.TrimSuffix(p, ".git")
656 p = strings.TrimSuffix(p, ".git/")
657
658 err = ioutil.WriteFile(path.Join(p, filename), []byte((content)), 0777)
659 checkFatal(t, err)
660
661 index, err := repo.Index()
662 checkFatal(t, err)
663 defer index.Free()
664
665 err = index.AddByPath(filename)
666 checkFatal(t, err)
667
668 newTreeOID, err := index.WriteTreeTo(repo)
669 checkFatal(t, err)
670
671 newTree, err := repo.LookupTree(newTreeOID)
672 checkFatal(t, err)
673 defer newTree.Free()
674
675 commitId, err := repo.CreateCommit("HEAD", signature(), signature(), fmt.Sprintf("add %s", filename), newTree, headCommit)
676 checkFatal(t, err)
677
678 commit, err := repo.LookupCommit(commitId)
679 checkFatal(t, err)
680
681 tree, err := commit.Tree()
682 checkFatal(t, err)
683
684 return commit, tree
685}

Callers 2

TestApplyDiffAddfileFunction · 0.85
TestApplyToTreeFunction · 0.85

Calls 12

headCommitFunction · 0.85
checkFatalFunction · 0.85
signatureFunction · 0.85
AddByPathMethod · 0.80
WriteTreeToMethod · 0.80
LookupTreeMethod · 0.80
CreateCommitMethod · 0.80
LookupCommitMethod · 0.80
TreeMethod · 0.80
FreeMethod · 0.65
PathMethod · 0.45
IndexMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…