The friendly commit command glues the pieces together: turn the index into a tree, then commit that tree. Today you build that glue and produce a real commit straight from the staging area.
Commit the current index in one step by combining write-tree and commit-tree.
This is the command a user actually runs: commit. Everything under it already
exists, so the porcelain is pure glue. It calls write-tree to snapshot the
index into a root tree, then commit-tree to wrap that tree in a commit with the
given parents and message. The result is a commit id that captures the exact
staged state.
Notice how the layers stack: blobs hold file contents, trees hold directory
structure, a commit names one root tree plus metadata, and this porcelain drives
all three from the staging area. Staging the three files and committing with no
parent yields the same f18e98d3... we built by hand, now produced end to end
from real files. What is still missing is memory: this commit is not yet recorded
anywhere a branch can find it. Refs, next chapter, fix that.
// write-tree the index, then commit-tree the resulting root treefunc (r *Repo) Commit(ix *Index, parents []string, ident, msg string) (string, error) {tree, err := r.WriteTreeFromIndex(ix)if err != nil { return "", err }return r.CommitTree(tree, parents, ident, msg)}