MCPcopy Create free account
hub / github.com/go-git/go-git / BuildTree

Method BuildTree

worktree_commit.go:177–193  ·  view source on GitHub ↗

BuildTree builds the tree objects and push its to the storer, the hash of the root tree is returned.

(idx *index.Index, opts *CommitOptions)

Source from the content-addressed store, hash-verified

175// BuildTree builds the tree objects and push its to the storer, the hash
176// of the root tree is returned.
177func (h *buildTreeHelper) BuildTree(idx *index.Index, opts *CommitOptions) (plumbing.Hash, error) {
178 if len(idx.Entries) == 0 && (opts == nil || !opts.AllowEmptyCommits) {
179 return plumbing.ZeroHash, ErrEmptyCommit
180 }
181
182 const rootNode = ""
183 h.trees = map[string]*object.Tree{rootNode: {}}
184 h.entries = map[string]*object.TreeEntry{}
185
186 for _, e := range idx.Entries {
187 if err := h.commitIndexEntry(e); err != nil {
188 return plumbing.ZeroHash, err
189 }
190 }
191
192 return h.copyTreeToStorageRecursive(rootNode, h.trees[rootNode])
193}
194
195func (h *buildTreeHelper) commitIndexEntry(e *index.Entry) error {
196 parts := strings.Split(e.Name, "/")

Callers 1

CommitMethod · 0.95

Calls 2

commitIndexEntryMethod · 0.95

Tested by

no test coverage detected