fix(git): guard remote branch deletion and skip applied cherry-picks

- Delete a remote branch only when the upstream (read from
  branch.<name>.remote and branch.<name>.merge) has the same name;
  otherwise refuse with REMOTE_BRANCH_MISMATCH before deleting anything.
- Without force, require the branch to be merged into HEAD before
  deleting its remote branch, so pushed unmerged commits are not lost.
- Cherry-pick integration selects only commits not yet applied to the
  target and skips merge commits.
- Create worktrees from a remote-only base as origin/<branch>.
- Show the upstream name in the branch delete dialog and update the
  worktree delete option text and git docs.
This commit is contained in:
Chris Scott committed 2026-10-03 22:51:03 -04:00
1 parent 53238a6324
commit 84e14c4600
10 files changed
+231 -25

No files matched your search

@@ -130,6 +130,24 @@ describe('CreateWorktreeDialog', () => {
})
})
it('submits a remote-only base branch qualified with origin', async () => {
const user = userEvent.setup()
renderDialog()
await user.type(screen.getByPlaceholderText('feature/my-branch'), 'my-new-branch')
await user.click(screen.getByRole('combobox'))
await user.click(screen.getByRole('option', { name: /release/ }))
await user.click(screen.getByRole('button', { name: 'Create Worktree' }))
await waitFor(() => expect(createRepo).toHaveBeenCalledTimes(1))
expect(createRepo).toHaveBeenCalledWith({
repoUrl,
branch: 'my-new-branch',
useWorktree: true,
baseBranch: 'origin/release',
})
})
it('prompts to use existing mode when a new branch name already exists', async () => {
const user = userEvent.setup()
renderDialog()
@@ -240,7 +240,7 @@ export function CreateWorktreeDialog({
</>
)}
{remoteBranches.map((branch) => (
<SelectItem key={`remote-${branch.name}`} value={branch.shortName}>
<SelectItem key={`remote-${branch.name}`} value={`origin/${branch.shortName}`}>
<div className="flex items-center gap-2">
<GitBranch className="w-3.5 h-3.5 text-info" />
<span>{branch.shortName}</span>
+1 -1
View File
@@ -33,7 +33,7 @@ import { ASSISTANT_REPO_ID } from "@opencode-manager/shared/utils"
const DELETE_BRANCH_OPTIONS: Array<RadioOption<DeleteBranchChoice>> = [
{ value: 'none', label: 'Keep branch', description: 'Leave the branch in the parent repository.' },
{ value: 'local', label: 'Delete local branch', description: 'Remove the branch from the parent repository.' },
{ value: 'local-and-remote', label: 'Delete local and remote branch', description: 'Also delete the branch from origin.' },
{ value: 'local-and-remote', label: 'Delete local and remote branch', description: 'Also delete its remote branch when it has the same name and is merged.' },
]
interface RepoCardWrapperProps {
@@ -72,4 +72,21 @@ describe('BranchesTab', () => {
expect(screen.getByRole('textbox', { name: 'New name for branch feature' })).toBeInTheDocument()
})
it('shows the upstream branch name in the delete dialog', async () => {
vi.mocked(listBranches).mockResolvedValue({
branches: [
{ name: 'main', type: 'local', current: true },
{ name: 'feature', type: 'local', current: false, upstream: 'origin/feature' },
],
status: { ahead: 0, behind: 0 },
})
const user = userEvent.setup()
render(<BranchesTab repoId={1} currentBranch="main" />, { wrapper: createWrapper() })
await user.click(await screen.findByRole('button', { name: 'Actions for feature' }))
await user.click(await screen.findByRole('menuitem', { name: 'Delete' }))
expect(await screen.findByText('origin/feature')).toBeInTheDocument()
})
})
@@ -423,7 +423,8 @@ export function BranchesTab({ repoId, currentBranch }: BranchesTabProps) {
checked={deleteRemote}
onCheckedChange={(checked) => setDeleteRemote(checked === true)}
/>
Also delete remote branch
Also delete remote branch{' '}
<span className="font-mono">{branchToDelete.upstream}</span>
</label>
)}
</div>