Skip to content

feat: add poly branch delete command#63

Open
oeisenberg wants to merge 8 commits intomainfrom
feat/branch-delete
Open

feat: add poly branch delete command#63
oeisenberg wants to merge 8 commits intomainfrom
feat/branch-delete

Conversation

@oeisenberg
Copy link
Copy Markdown
Contributor

@oeisenberg oeisenberg commented Apr 2, 2026

Summary

Adds poly branch delete — an interactive command for deleting branches, following the same UX pattern as poly review delete.

Motivation

Branch deletion was already implemented in the backend (project.delete_branch()) but not exposed through the CLI.

Changes

  • Added delete subcommand to poly branch with optional branch_name argument
  • Interactive checkbox selection (via questionary) when no branch name is provided
  • Direct deletion mode when branch name is passed as argument
  • JSON output mode support (--json)
  • Filters out main branch (cannot be deleted)
  • 16 new unit tests covering all code paths

Test strategy

  • Added/updated unit tests
  • Manual CLI testing (poly <command>)
  • Tested against a live Agent Studio project
  • N/A (docs, config, or trivial change)
image image

Checklist

  • ruff check . and ruff format --check . pass
  • pytest passes (431 tests)
  • No breaking changes to the poly CLI interface (or migration path documented)
  • Commit messages follow conventional commits

🤖 Generated with Claude Code

Mirrors the style of `poly review delete` — supports direct deletion via
branch name argument or interactive checkbox selection for bulk deletion.
Includes JSON output mode and full error handling.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions

This comment has been minimized.

`get_branches()` returns `{name: id}` — the existence check was against
`.values()` (IDs) instead of keys (names), so deletion always raised
"does not exist".

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions

This comment has been minimized.

Downgrade `logger.error` to `logger.debug` in `delete_branch` so the
full API error body (HTML) is only shown with `--verbose`, matching the
pattern from 8e54b2d.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions

This comment has been minimized.

- SDK: use `str(e)` (e.g. "404 Client Error: Not Found for url: ...")
  instead of `e.response.text` (raw HTML) when response isn't JSON
- sync_client: re-raise SourcererAPIError so the CLI can display it
- project: simplify delete_branch now that errors propagate via exception

Output now matches `poly review` style:
  Error: API request failed: 404 Client Error: Not Found for url: ...

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions

This comment has been minimized.

- Add argcomplete completer for `poly branch delete <TAB>` that lists
  deletable branch names from the project
- Add `questionary.confirm` step before deleting in both direct and
  interactive modes (skipped in --json mode)
- Update tests to mock the new confirmation prompt

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions

This comment has been minimized.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions

This comment has been minimized.

argcomplete calls completers with (prefix, action, parser, parsed_args)
but our completer only accepted (prefix, parsed_args) — the mismatch
caused a silent crash that fell back to file completion.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions

This comment has been minimized.

- Fix delete_branch to fetch sequence from branch projection endpoint
  instead of the /sequence endpoint which 404s on the ADK API
- Fix tab completer to use read_project_config (supports parent dir
  traversal) instead of the raw dataclass constructor which always failed
- Fix `poly completion zsh` crash caused by missing verbose attribute
  on the completion subparser
- Suppress option flags from polluting branch name completions

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

Coverage Report

Base (main) PR Change
71.5% 71.5% +0.0% ✅

Changed file coverage

File Coverage Change
poly/handlers/sdk.py 14.2% -0.3% ⚠️
poly/cli.py 43.2% +3.5% ✅

@oeisenberg oeisenberg requested a review from Ruari-Phipps April 2, 2026 15:57
@oeisenberg
Copy link
Copy Markdown
Contributor Author

oeisenberg commented Apr 2, 2026

@Ruari-Phipps

  1. --json doesn't y/n approval
    • Does --json imply --force or should we add a force command.
  2. It also feels odd to have the --json flag on the branch not delete command.
    • Is it okay to move this the sub_parsers instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant