-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit.go
More file actions
30 lines (27 loc) · 851 Bytes
/
commit.go
File metadata and controls
30 lines (27 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package g
import "fmt"
// Commit writes the Commit provided in the Object Store.
func (r *Repository) Commit(commit *Commit) (Sha, error) {
idx, err := r.Index()
if err != nil {
return Sha{}, fmt.Errorf("reading index: %w", err)
}
idxFiles, err := idx.Files()
if err != nil {
return Sha{}, fmt.Errorf("reading index files: %w", err)
}
root := ObjectTree(idxFiles, r.workingDirectory())
tree, err := r.writeTreeRecursive(root)
if err != nil {
return Sha{}, fmt.Errorf("writing tree: %w", err)
}
previousCommits, err := r.previousCommits()
if err != nil {
return Sha{}, fmt.Errorf("reading previous commits: %w", err)
}
commit.Tree = tree
commit.Parents = previousCommits
return r.writeCommit(commit)
}
// Free-function shims for migration.
func CreateCommit(commit *Commit) (Sha, error) { return defaultRepo.Commit(commit) }