Start tasks in a repo with no commits
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user