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
+11
View File
@@ -119,6 +119,17 @@ func (m *Manager) createTask(ctx context.Context, project api.Project, t api.Tas
t.Status = api.TaskStatusActive
t.CreatedAt = time.Now().UTC()
if base == project.DefaultBranch {
creator, err := m.store.GetUser(ctx, t.CreatedBy)
if err != nil {
return api.Task{}, err
}
err = git.EnsureBranchCommit(ctx, project.RepoPath, base, git.IdentityEnv(creator.GitName, creator.GitEmail))
if err != nil {
return api.Task{}, err
}
}
var err error
t.BaseRef, err = git.AddWorktree(ctx, project.RepoPath, t.WorktreePath, t.Branch, base)
if err != nil {
+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