From 6dcd26901b862aa680a1cb501f24183bcf854abc Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Thu, 26 Mar 2026 08:28:02 +0000 Subject: fix: auto-create story branch if missing at clone time If git checkout of the story branch fails (branch never pushed to bare repo), create it from HEAD and push to origin instead of hard-failing the task. Co-Authored-By: Claude Sonnet 4.6 --- internal/executor/container.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/executor/container.go b/internal/executor/container.go index 95717b4..d90a273 100644 --- a/internal/executor/container.go +++ b/internal/executor/container.go @@ -133,7 +133,14 @@ func (r *ContainerRunner) Run(ctx context.Context, t *task.Task, e *storage.Exec if storyBranch != "" { r.Logger.Info("checking out story branch", "branch", storyBranch) if out, err := r.command(ctx, "git", "-C", workspace, "checkout", storyBranch).CombinedOutput(); err != nil { - return fmt.Errorf("git checkout story branch %q failed: %w\n%s", storyBranch, err, string(out)) + // Branch doesn't exist in the remote yet — create it from HEAD and push. + r.Logger.Warn("story branch not found, creating from HEAD", "branch", storyBranch) + if out2, err2 := r.command(ctx, "git", "-C", workspace, "checkout", "-b", storyBranch).CombinedOutput(); err2 != nil { + return fmt.Errorf("git checkout story branch %q failed: %w\n%s\ncreate attempt: %s", storyBranch, err, string(out), string(out2)) + } + if out2, err2 := r.command(ctx, "git", "-C", workspace, "push", "origin", storyBranch).CombinedOutput(); err2 != nil { + r.Logger.Warn("push of auto-created story branch failed", "branch", storyBranch, "error", err2, "output", string(out2)) + } } } if err = os.Chmod(workspace, 0755); err != nil { -- cgit v1.2.3