Skip to content

feat: add --attach flag to workspace create for existing branches#15

Merged
ckrough merged 5 commits intomainfrom
xenodochial-sammet
Dec 21, 2025
Merged

feat: add --attach flag to workspace create for existing branches#15
ckrough merged 5 commits intomainfrom
xenodochial-sammet

Conversation

@ckrough
Copy link
Owner

@ckrough ckrough commented Dec 21, 2025

Summary

  • Add --attach / -a flag to workspace create command
  • When used, attaches to an existing branch instead of creating a new one
  • Workspace name matches the branch name (with slashes converted to hyphens)

Usage

# Attach to existing branch
as workspace create feature/auth --attach

# Short form
as workspace create feature/auth -a

Changes

File Description
src/agentspaces/infrastructure/git.py Add branch_exists() and worktree_add_existing()
src/agentspaces/modules/workspace/worktree.py Add sanitize_branch_name() and attach_worktree()
src/agentspaces/modules/workspace/service.py Add attach_branch parameter to create()
src/agentspaces/cli/workspace.py Add --attach / -a CLI flag

Test plan

  • All 309 tests pass
  • Linter passes (ruff check)
  • Type checker passes (mypy)
  • Manual test: as workspace create <existing-branch> --attach
  • Manual test: as workspace create feature/auth --attach (branch with slash)
  • Manual test: Error when branch doesn't exist

Allow creating a workspace that attaches to an existing branch without
creating a new branch. The workspace name matches the branch name.

Usage:
  as workspace create feature/auth --attach

Key changes:
- Add branch_exists() and worktree_add_existing() to git infrastructure
- Add sanitize_branch_name() to handle branches with slashes (feature/auth -> feature-auth)
- Add attach_worktree() for creating worktrees from existing branches
- Add attach_branch parameter to WorkspaceService.create()
- Add --attach/-a CLI flag to workspace create command

Closes the feature request for workspace and branch handling.
- Replace contextlib.suppress(Exception) with explicit try/except and
  logging in service.py cleanup path
- Add logging for branch_delete() failures in git.py
- Add test for "branch already checked out" error scenario
- Add CLI integration tests for --attach flag using typer's CliRunner
@ckrough ckrough merged commit a01bbc4 into main Dec 21, 2025
4 checks passed
@ckrough ckrough deleted the xenodochial-sammet branch December 21, 2025 21:04
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