Start tasks in a repo with no commits

This commit is contained in:
Ian Gulliver
2026-10-22 11:46:48 -07:00
parent 48741e8cbb
commit b8984d30f0
2 changed files with 32 additions and 0 deletions
+21
View File
@@ -75,6 +75,27 @@ func AddWorktree(ctx context.Context, repo, path, branch, base string) (string,
return sha, nil
}
func EnsureBranchCommit(ctx context.Context, repo, branch string, env []string) error {
_, _, code, err := runCode(ctx, repo, nil, "rev-parse", "--verify", "--quiet", "refs/heads/"+branch+"^{commit}")
if err != nil || code == 0 {
return err
}
refs, err := run(ctx, repo, "for-each-ref", "--count=1")
if err != nil || refs != "" {
return err
}
tree, err := run(ctx, repo, "mktree")
if err != nil {
return err
}
commit, err := runEnv(ctx, repo, env, "commit-tree", tree, "-m", "Initial commit")
if err != nil {
return err
}
_, err = run(ctx, repo, "update-ref", "refs/heads/"+branch, commit, "")
return err
}
func AddDetachedWorktree(ctx context.Context, repo, path, commit string) error {
_, err := run(ctx, repo, "worktree", "add", "--detach", path, commit)
return err