Unified · Split
| @@ -400,95 +400,73 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions · 399 unmodified lines | ||
| 400 | 400 | }); |
| 401 | 401 | }, [pendingDefaultBranchAction, runGitActionWithToast]); |
| 402 | 402 | |
| 403 | + const checkoutNewBranchAndRunAction = useCallback( | |
| 404 | + (actionParams: { | |
| 405 | + action: GitStackedAction; | |
| 406 | + commitMessage?: string; | |
| 407 | + forcePushOnlyProgress?: boolean; | |
| 408 | + onConfirmed?: () => void; | |
| 409 | + }) => { | |
| 410 | + const branchName = resolveAutoFeatureBranchName( | |
| 411 | + branchList?.branches.map((branch) => branch.name) ?? [], | |
| 412 | + ); | |
| 413 | + | |
| 414 | + const checkoutPromise = createBranchAndCheckoutMutation.mutateAsync(branchName); | |
| 415 | + toastManager.promise(checkoutPromise, { | |
| 416 | + loading: { title: `Creating ${branchName}...`, data: threadToastData }, | |
| 417 | + success: () => ({ | |
| 418 | + title: `Checked out ${branchName}`, | |
| 419 | + data: threadToastData, | |
| 420 | + }), | |
| 421 | + error: (error) => ({ | |
| 422 | + title: "Failed to checkout feature branch", | |
| 423 | + description: error instanceof Error ? error.message : "An error occurred.", | |
| 424 | + data: threadToastData, | |
| 425 | + }), | |
| 426 | + }); | |
| 427 | + | |
| 428 | + void checkoutPromise | |
| 429 | + .then(() => { | |
| 430 | + const statusOverride = gitStatusForActions | |
| 431 | + ? { ...gitStatusForActions, branch: branchName, pr: null } | |
| 432 | + : null; | |
| 433 | + return runGitActionWithToast({ | |
| 434 | + ...actionParams, | |
| 435 | + skipDefaultBranchPrompt: true, | |
| 436 | + statusOverride, | |
| 437 | + isDefaultBranchOverride: false, | |
| 438 | + }); | |
| 439 | + }) | |
| 440 | + .catch(() => undefined); | |
| 441 | + }, | |
| 442 | + [ | |
| 443 | + branchList?.branches, | |
| 444 | + createBranchAndCheckoutMutation, | |
| 445 | + gitStatusForActions, | |
| 446 | + runGitActionWithToast, | |
| 447 | + threadToastData, | |
| 448 | + ], | |
| 449 | + ); | |
| 450 | + | |
| 403 | 451 | const checkoutFeatureBranchAndContinuePendingAction = useCallback(() => { |
| 404 | 452 | if (!pendingDefaultBranchAction) return; |
| 405 | 453 | const pendingAction = pendingDefaultBranchAction; |
| 406 | − const branchName = resolveAutoFeatureBranchName(branchList?.branches.map((branch) => branch.name) ?? []); | |
| 407 | 454 | setPendingDefaultBranchAction(null); |
| 408 | − | |
| 409 | − const checkoutPromise = createBranchAndCheckoutMutation.mutateAsync(branchName); | |
| 410 | − toastManager.promise(checkoutPromise, { | |
| 411 | − loading: { title: `Creating ${branchName}...`, data: threadToastData }, | |
| 412 | − success: () => ({ | |
| 413 | − title: `Checked out ${branchName}`, | |
| 414 | − data: threadToastData, | |
| 415 | − }), | |
| 416 | − error: (error) => ({ | |
| 417 | − title: "Failed to checkout feature branch", | |
| 418 | − description: error instanceof Error ? error.message : "An error occurred.", | |
| 419 | − data: threadToastData, | |
| 420 | − }), | |
| 421 | − }); | |
| 422 | − | |
| 423 | − void checkoutPromise | |
| 424 | − .then(() => { | |
| 425 | − const statusOverride = gitStatusForActions | |
| 426 | − ? { ...gitStatusForActions, branch: branchName, pr: null } | |
| 427 | − : null; | |
| 428 | − return runGitActionWithToast({ | |
| 429 | − ...pendingAction, | |
| 430 | − skipDefaultBranchPrompt: true, | |
| 431 | − statusOverride, | |
| 432 | − isDefaultBranchOverride: false, | |
| 433 | − }); | |
| 434 | − }) | |
| 435 | − .catch(() => undefined); | |
| 436 | − }, [ | |
| 437 | − branchList?.branches, | |
| 438 | − createBranchAndCheckoutMutation, | |
| 439 | − gitStatusForActions, | |
| 440 | − pendingDefaultBranchAction, | |
| 441 | − runGitActionWithToast, | |
| 442 | − threadToastData, | |
| 443 | − ]); | |
| 455 | + checkoutNewBranchAndRunAction(pendingAction); | |
| 456 | + }, [pendingDefaultBranchAction, checkoutNewBranchAndRunAction]); | |
| 444 | 457 | |
| 445 | 458 | const runDialogActionOnNewBranch = useCallback(() => { |
| 446 | 459 | if (!isCommitDialogOpen) return; |
| 447 | − const action: GitStackedAction = "commit"; | |
| 448 | 460 | const commitMessage = dialogCommitMessage.trim(); |
| 449 | − const branchName = resolveAutoFeatureBranchName(branchList?.branches.map((branch) => branch.name) ?? []); | |
| 450 | 461 | |
| 451 | 462 | setIsCommitDialogOpen(false); |
| 452 | 463 | setDialogCommitMessage(""); |
| 453 | 464 | |
| 454 | − const checkoutPromise = createBranchAndCheckoutMutation.mutateAsync(branchName); | |
| 455 | − toastManager.promise(checkoutPromise, { | |
| 456 | − loading: { title: `Creating ${branchName}...`, data: threadToastData }, | |
| 457 | − success: () => ({ | |
| 458 | − title: `Checked out ${branchName}`, | |
| 459 | − data: threadToastData, | |
| 460 | − }), | |
| 461 | − error: (error) => ({ | |
| 462 | − title: "Failed to checkout feature branch", | |
| 463 | − description: error instanceof Error ? error.message : "An error occurred.", | |
| 464 | − data: threadToastData, | |
| 465 | − }), | |
| 465 | + checkoutNewBranchAndRunAction({ | |
| 466 | + action: "commit", | |
| 467 | + ...(commitMessage ? { commitMessage } : {}), | |
| 466 | 468 | }); |
| 467 | − | |
| 468 | − void checkoutPromise | |
| 469 | − .then(() => { | |
| 470 | − const statusOverride = gitStatusForActions | |
| 471 | − ? { ...gitStatusForActions, branch: branchName, pr: null } | |
| 472 | − : null; | |
| 473 | − return runGitActionWithToast({ | |
| 474 | − action, | |
| 475 | − ...(commitMessage ? { commitMessage } : {}), | |
| 476 | − skipDefaultBranchPrompt: true, | |
| 477 | − statusOverride, | |
| 478 | − isDefaultBranchOverride: false, | |
| 479 | − }); | |
| 480 | − }) | |
| 481 | − .catch(() => undefined); | |
| 482 | − }, [ | |
| 483 | − branchList?.branches, | |
| 484 | − createBranchAndCheckoutMutation, | |
| 485 | − dialogCommitMessage, | |
| 486 | − gitStatusForActions, | |
| 487 | − isCommitDialogOpen, | |
| 488 | − runGitActionWithToast, | |
| 489 | − setIsCommitDialogOpen, | |
| 490 | − threadToastData, | |
| 491 | − ]); | |
| 469 | + }, [isCommitDialogOpen, dialogCommitMessage, checkoutNewBranchAndRunAction]); | |
| 492 | 470 | |
| 493 | 471 | const runQuickAction = useCallback(() => { |
| 494 | 472 | if (quickAction.kind === "open_pr") { |