Artifact 2d3aa1bd1de951f0364d6ecb97823d7292f0c0fd23e56d5e61aff193384ff057:
- File
internal/zitcli/create.go
— part of check-in
[9f78830644]
at
2026-08-18 01:47:06
on branch trunk
— repo.add: create an empty repository or adopt one by cloning
Two cases quarry could not do at all. create runs zit init at the path — the 'host my project here' case. clone copies a remote in and records a mirror for it, because adopting a remote repository and then not tracking it is almost never what anyone meant.
Cloning takes the bulk lane: a large repository is minutes of network, and an admin asking for it is not a reason to run it unbounded.
Both refuse a non-empty target and undo what they made if a later step fails — the store, the OLTP row, or both. Verified: sqlite.org/docsrc adopted in 14s (5,116 check-ins, serving in 2.24ms), and a clone from an unreachable URL leaves no directory, no registration and no row. (user: dmestas, size: 1607) [annotate] [blame] [check-ins using]
package zitcli import ( "bytes" "context" "fmt" "os/exec" "strings" "time" "craftdesign.group/quarry/internal/timing" ) // Init creates an empty repository at dir, creating dir if needed. // // A package function rather than a Client method because a Client is // bound to a repository that already exists; this is what makes one. func Init(ctx context.Context, dir string) error { return create(ctx, "init", []string{"init", dir}, dir) } // Clone copies the repository served at url into dir. // // zit saves url as dir's default remote, and never with a password: a // `user:secret@host` URL is stored as `user@host`. That is worth knowing // here because quarry keeps its own mirror configuration — the saved // remote is a convenience for anyone running zit by hand in that // directory, not the thing quarry's scheduler reads. func Clone(ctx context.Context, url, dir string) error { return create(ctx, "clone", []string{"clone", url, dir}, dir) } // create runs a repository-making verb. These are the two zit calls // with no repository to name, so they take neither -R nor a working // directory — the target is an argument. func create(ctx context.Context, verb string, args []string, dir string) error { if ctx == nil { ctx = context.Background() } start := time.Now() cmd := exec.CommandContext(ctx, "zit", args...) var stderr bytes.Buffer cmd.Stderr = &stderr _, err := cmd.Output() timing.Record(ctx, timing.Zit, time.Since(start)) if err != nil { return fmt.Errorf("zitcli: %s %s: %w: %s", verb, dir, err, strings.TrimSpace(stderr.String())) } return nil }