handleCleanConfirmationKeys handles keyboard input for the clean confirmation dialog.
(msg tea.KeyMsg)
| 1738 | |
| 1739 | // handleCleanConfirmationKeys handles keyboard input for the clean confirmation dialog. |
| 1740 | func (a App) handleCleanConfirmationKeys(msg tea.KeyMsg) (tea.Model, tea.Cmd) { |
| 1741 | switch msg.String() { |
| 1742 | case "esc": |
| 1743 | a.picker.CancelCleanConfirmation() |
| 1744 | return a, nil |
| 1745 | case "up", "k": |
| 1746 | a.picker.CleanConfirmMoveUp() |
| 1747 | return a, nil |
| 1748 | case "down", "j": |
| 1749 | a.picker.CleanConfirmMoveDown() |
| 1750 | return a, nil |
| 1751 | case "enter": |
| 1752 | cc := a.picker.GetCleanConfirmation() |
| 1753 | if cc == nil { |
| 1754 | return a, nil |
| 1755 | } |
| 1756 | |
| 1757 | option := a.picker.GetCleanOption() |
| 1758 | if option == CleanOptionCancel { |
| 1759 | a.picker.CancelCleanConfirmation() |
| 1760 | return a, nil |
| 1761 | } |
| 1762 | |
| 1763 | prdName := cc.EntryName |
| 1764 | branch := cc.Branch |
| 1765 | clearBranch := option == CleanOptionRemoveAll |
| 1766 | baseDir := a.baseDir |
| 1767 | worktreePath := git.WorktreePathForPRD(baseDir, prdName) |
| 1768 | |
| 1769 | return a, func() tea.Msg { |
| 1770 | // Remove the worktree |
| 1771 | if err := git.RemoveWorktree(baseDir, worktreePath); err != nil { |
| 1772 | return cleanResultMsg{ |
| 1773 | prdName: prdName, |
| 1774 | success: false, |
| 1775 | message: fmt.Sprintf("Failed to remove worktree: %s", err.Error()), |
| 1776 | } |
| 1777 | } |
| 1778 | |
| 1779 | // Delete branch if requested |
| 1780 | if clearBranch && branch != "" { |
| 1781 | if err := git.DeleteBranch(baseDir, branch); err != nil { |
| 1782 | return cleanResultMsg{ |
| 1783 | prdName: prdName, |
| 1784 | success: true, |
| 1785 | message: fmt.Sprintf("Removed worktree but failed to delete branch: %s", err.Error()), |
| 1786 | clearBranch: false, |
| 1787 | } |
| 1788 | } |
| 1789 | } |
| 1790 | |
| 1791 | msg := fmt.Sprintf("Removed worktree for %s", prdName) |
| 1792 | if clearBranch && branch != "" { |
| 1793 | msg = fmt.Sprintf("Removed worktree and deleted branch %s", branch) |
| 1794 | } |
| 1795 | return cleanResultMsg{ |
| 1796 | prdName: prdName, |
| 1797 | success: true, |
no test coverage detected