runWorktreeStep runs a worktree setup step asynchronously.
(step WorktreeSpinnerStep, baseDir, worktreePath, branchName string)
| 1625 | |
| 1626 | // runWorktreeStep runs a worktree setup step asynchronously. |
| 1627 | func (a *App) runWorktreeStep(step WorktreeSpinnerStep, baseDir, worktreePath, branchName string) tea.Cmd { |
| 1628 | switch step { |
| 1629 | case SpinnerStepCreateBranch: |
| 1630 | return func() tea.Msg { |
| 1631 | // CreateWorktree handles both branch creation and worktree addition |
| 1632 | if err := git.CreateWorktree(baseDir, worktreePath, branchName); err != nil { |
| 1633 | return worktreeStepResultMsg{step: SpinnerStepCreateBranch, err: err} |
| 1634 | } |
| 1635 | return worktreeStepResultMsg{step: SpinnerStepCreateBranch} |
| 1636 | } |
| 1637 | |
| 1638 | case SpinnerStepRunSetup: |
| 1639 | setupCmd := a.config.Worktree.Setup |
| 1640 | return func() tea.Msg { |
| 1641 | cmd := exec.Command("sh", "-c", setupCmd) |
| 1642 | cmd.Dir = worktreePath |
| 1643 | if out, err := cmd.CombinedOutput(); err != nil { |
| 1644 | return worktreeStepResultMsg{ |
| 1645 | step: SpinnerStepRunSetup, |
| 1646 | err: fmt.Errorf("%s\n%s", err.Error(), strings.TrimSpace(string(out))), |
| 1647 | } |
| 1648 | } |
| 1649 | return worktreeStepResultMsg{step: SpinnerStepRunSetup} |
| 1650 | } |
| 1651 | } |
| 1652 | return nil |
| 1653 | } |
| 1654 | |
| 1655 | // handleWorktreeStepResult handles the result of a worktree setup step. |
| 1656 | func (a App) handleWorktreeStepResult(msg worktreeStepResultMsg) (tea.Model, tea.Cmd) { |
no test coverage detected