BuildTree builds the tree objects and push its to the storer, the hash of the root tree is returned.
(idx *index.Index, opts *CommitOptions)
| 175 | // BuildTree builds the tree objects and push its to the storer, the hash |
| 176 | // of the root tree is returned. |
| 177 | func (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 | |
| 195 | func (h *buildTreeHelper) commitIndexEntry(e *index.Entry) error { |
| 196 | parts := strings.Split(e.Name, "/") |
no test coverage detected