* Rebase the current branch in the worktree onto the latest base branch. * Uses `git rebase --onto `. * * - If a rebase is already in progress, throws RebaseInProgressError * - On conflict, throws MergeConflictError with ConflictOp.REBASE (preserves r
(worktreePath: string, baseBranch: string)
| 557 | * - On non-conflict failure, auto-aborts to keep repo clean |
| 558 | */ |
| 559 | async rebase(worktreePath: string, baseBranch: string): Promise<void> { |
| 560 | // Pre-check 1: worktree must be clean (no uncommitted tracked changes) |
| 561 | if (!(await this.isWorktreeClean(worktreePath))) { |
| 562 | throw new WorktreeDirtyError(worktreePath); |
| 563 | } |
| 564 | |
| 565 | // Pre-check 2: no rebase already in progress |
| 566 | if (await this.isRebaseInProgress(worktreePath)) { |
| 567 | throw new RebaseInProgressError(); |
| 568 | } |
| 569 | |
| 570 | // Get current branch name |
| 571 | const currentBranchRaw = await execGit(worktreePath, ['rev-parse', '--abbrev-ref', 'HEAD']); |
| 572 | const taskBranch = currentBranchRaw.trim(); |
| 573 | |
| 574 | // Calculate merge-base |
| 575 | const mergeBaseRaw = await execGit(worktreePath, ['merge-base', baseBranch, taskBranch]); |
| 576 | const mergeBase = mergeBaseRaw.trim(); |
| 577 | |
| 578 | try { |
| 579 | await execGit(worktreePath, ['rebase', '--onto', baseBranch, mergeBase, taskBranch]); |
| 580 | } catch (err) { |
| 581 | // Check if it's a conflict |
| 582 | if (await this.isRebaseInProgress(worktreePath)) { |
| 583 | const conflictedFiles = await this.getConflictedFilesIn(worktreePath); |
| 584 | if (conflictedFiles.length > 0) { |
| 585 | throw new MergeConflictError(conflictedFiles, ConflictOp.REBASE); |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | // Non-conflict failure: auto-abort to keep repo clean |
| 590 | try { |
| 591 | await execGit(worktreePath, ['rebase', '--abort']); |
| 592 | } catch { |
| 593 | // ignore abort failure |
| 594 | } |
| 595 | throw err; |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | /** |
| 600 | * Get the current Git operation status of a worktree. |
no test coverage detected