StoreTree writes the given file tree to the repository and returns its hash.
(contents map[string]TreeChild)
| 549 | |
| 550 | // StoreTree writes the given file tree to the repository and returns its hash. |
| 551 | func (repo *GitRepo) StoreTree(contents map[string]TreeChild) (string, error) { |
| 552 | var lines []string |
| 553 | for path, obj := range contents { |
| 554 | objHash, err := obj.Store(repo) |
| 555 | if err != nil { |
| 556 | return "", err |
| 557 | } |
| 558 | mode := "040000" |
| 559 | if obj.Type() == "blob" { |
| 560 | mode = "100644" |
| 561 | } |
| 562 | line := fmt.Sprintf("%s %s %s\t%s", mode, obj.Type(), objHash, path) |
| 563 | lines = append(lines, line) |
| 564 | } |
| 565 | stdin := strings.NewReader(strings.Join(lines, "\n")) |
| 566 | var stdout bytes.Buffer |
| 567 | var stderr bytes.Buffer |
| 568 | args := []string{"mktree"} |
| 569 | err := repo.runGitCommandWithIO(stdin, &stdout, &stderr, args...) |
| 570 | if err != nil { |
| 571 | message := strings.TrimSpace(stderr.String()) |
| 572 | return "", fmt.Errorf("failure storing a git tree, %v: %q", err, message) |
| 573 | } |
| 574 | return strings.TrimSpace(stdout.String()), nil |
| 575 | } |
| 576 | |
| 577 | func (repo *GitRepo) readBlob(objHash string) (*Blob, error) { |
| 578 | out, err := repo.runGitCommand("cat-file", "-p", objHash) |
no test coverage detected