Skip to content

fix(shared,desktop): allow slashes in custom branch prefixes - #6151

Open
prayagtushar wants to merge 1 commit into
ParadevAI:mainfrom
prayagtushar:fix/branch-prefix-slashes
Open

prayagtushar wants to merge 1 commit into
ParadevAI:mainfrom
prayagtushar:fix/branch-prefix-slashes

Conversation

@prayagtushar

@prayagtushar prayagtushar commented Aug 4, 2026 •

Copy link
Copy Markdown

What & why

fixes #5367

The custom branch prefix ran through sanitizeSegment, which strips /, so
user/my-name was saved as usermy-name.

It now uses sanitizeBranchName, which cleans each segment and keeps the
slashes. The 50 character cap is unchanged, and author/GitHub prefixes stay
single segments.

Both the settings inputs and the resolvers needed it. The inputs are what you
watch eat the slash; the resolvers would strip it again when the branch is
created.

Prefixes saved before this fix stay mangled — retyping fixes them.

How I tested it

Settings → Git & worktrees → Branch prefix → Custom prefix, typed user/my-name:

  • before: input becomes usermy-name, preview usermy-name/branch-name
  • after: input keeps user/my-name, preview user/my-name/branch-name

Created a workspace and got user/my-name/<slug>.

Checklist

  • PR title follows conventional commits (type(scope): subject)
  • bun run lint
  • bun run typecheck fails in @superset/ui
  • "Allow edits from maintainers" is checked on fork PRs

Summary by cubic

Allow slashes in custom branch prefixes and keep them across settings, previews, and branch creation. Sanitization now preserves case, caps the total prefix length to half of the branch-name budget, and blocks prefixes that collide (case-insensitively) with existing branch paths (fixes #5367).

  • Bug Fixes

    • Consistent custom-prefix sanitization in inputs and resolvers so saved values match the preview and created branch; returns null when the prefix sanitizes away.
    • Detect exact and ancestor collisions (case-insensitive) against existing branches in desktop and host-service.
  • Migration

    • Previously saved custom prefixes that lost slashes stay mangled; retype the prefix to fix.

Written for commit aebba84. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Improved custom branch-prefix sanitization across workspace, project, and Git settings.
    • Custom prefixes now preserve letter casing while enforcing valid branch-name formatting and length limits.
    • Improved detection of branch-prefix conflicts, including existing branches and nested paths.
    • Empty or fully sanitized prefixes are handled safely without disrupting branch creation.
    • Added consistent handling for custom, author-derived, GitHub-derived, unset, and disabled prefix modes.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Custom branch prefixes now use shared sanitization and collision detection. Sanitization preserves case, applies a segment length limit, and normalizes empty results. Workspace creation checks complete prefixes and ancestor paths.

Changes

Branch prefix handling

Layer / File(s) Summary
Shared prefix normalization and collision detection
packages/shared/src/workspace-launch/branch.ts, packages/shared/src/workspace-launch/branch.test.ts
Custom prefixes use bounded sanitization with case preservation. Resolution handles empty values. Tests cover complete prefixes, ancestor paths, case differences, and descendants.
Workspace creation collision integration
packages/host-service/src/trpc/router/workspace-creation/utils/branch-prefix.ts, apps/desktop/src/lib/trpc/routers/workspaces/utils/branch-prefix.ts
Workspace creation and desktop workspace routing use the shared collision helper.
Settings custom prefix handling
apps/desktop/src/renderer/routes/_authenticated/settings/components/BranchPrefixControl/BranchPrefixControl.tsx, apps/desktop/src/renderer/routes/_authenticated/settings/git/components/GitSettings/GitSettings.tsx, apps/desktop/src/renderer/routes/_authenticated/settings/project/$projectId/components/ProjectSettings/ProjectSettings.tsx
Settings controls sanitize custom prefixes before updating and persisting values.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes satisfy issue #5367 by preserving slashes in custom branch prefixes across settings and branch creation.
Out of Scope Changes check ✅ Passed The sanitization, collision handling, resolver updates, and tests are related to custom branch prefix behavior.
Title check ✅ Passed The title uses conventional commit format and clearly describes the main change: preserving slashes in custom branch prefixes.
Description check ✅ Passed The description explains the problem, implementation, testing steps, migration behavior, and checklist status.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR allows slash-separated custom branch prefixes in desktop settings and in shared and desktop prefix resolvers while retaining single-segment handling for author and GitHub prefixes.

  • Replaces segment-only sanitization with branch-name sanitization in three settings inputs.
  • Applies branch-aware sanitization and a 50-character effective limit during prefix resolution.
  • Leaves the persisted UI value uncapped in aggregate and does not account for ancestor ref collisions.

Confidence Score: 4/5

The PR should not merge until long multi-segment inputs are persisted consistently and ancestor Git ref collisions are rejected or handled.

Multi-segment prefixes can be saved beyond the promised effective limit, and prefixes containing an existing branch as an ancestor can reach Git worktree creation and fail there.

Files Needing Attention: apps/desktop/src/lib/trpc/routers/workspaces/utils/branch-prefix.ts and the three changed branch-prefix settings components

Important Files Changed

Filename Overview
packages/shared/src/workspace-launch/branch.ts Adds branch-aware custom-prefix sanitization with a 50-character effective limit; the shared resolver itself remains aligned with branch creation.
apps/desktop/src/lib/trpc/routers/workspaces/utils/branch-prefix.ts Preserves slash-separated custom prefixes but exact-only collision detection misses existing branches at ancestor ref paths.
apps/desktop/src/renderer/routes/_authenticated/settings/components/BranchPrefixControl/BranchPrefixControl.tsx Preserves slash-separated input but no longer enforces the 50-character aggregate limit before persistence.
apps/desktop/src/renderer/routes/_authenticated/settings/git/components/GitSettings/GitSettings.tsx Uses the same uncapped aggregate sanitizer when persisting global custom-prefix settings.
apps/desktop/src/renderer/routes/_authenticated/settings/project/$projectId/components/ProjectSettings/ProjectSettings.tsx Uses the same uncapped aggregate sanitizer when persisting project custom-prefix settings.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Input[Custom prefix input] --> UI[Settings sanitizer]
  UI --> DB[(Persisted setting)]
  DB --> Resolver[Branch prefix resolver]
  Resolver --> Combined[Prefix plus workspace slug]
  Combined --> Git[git worktree add -b]
Loading
Prompt To Fix All With AI
### Issue 1
apps/desktop/src/renderer/routes/_authenticated/settings/components/BranchPrefixControl/BranchPrefixControl.tsx:73
**Aggregate prefix limit is lost**

When a custom prefix contains multiple segments whose combined length exceeds 50 characters, `sanitizeBranchName` persists the full value because it limits each segment independently, while the shared and desktop resolvers truncate the effective prefix to 50 characters. This silently makes the saved setting differ from the prefix shown in previews and used for workspace branches.

### Issue 2
apps/desktop/src/lib/trpc/routers/workspaces/utils/branch-prefix.ts:43-48
**Ancestor ref collisions pass validation**

If a repository has an existing branch named `user` and the custom prefix is `user/team`, the changed sanitizer preserves the nested prefix while the later collision check compares only the complete `user/team` value. Workspace creation then asks Git to create a branch such as `user/team/task`, which fails because `refs/heads/user` cannot also be an ancestor directory.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "fix(shared,desktop): allow slashes in cu..." | Re-trigger Greptile

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/desktop/src/lib/trpc/routers/workspaces/utils/branch-prefix.ts`:
- Around line 41-49: Update the collision validation following sanitizedPrefix
generation to inspect every slash-delimited ancestor, not only the complete
prefix. When existingBranches contains any ancestor of a nested prefix such as
“user” for “user/my-name”, treat the prefix as unavailable and preserve the
existing collision-handling behavior before returning it.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e821bc6f-59b7-4bb6-89cc-8ffad69cc20a

📥 Commits

Reviewing files that changed from the base of the PR and between d530b98 and 2a8044b.

📒 Files selected for processing (5)
  • apps/desktop/src/lib/trpc/routers/workspaces/utils/branch-prefix.ts
  • apps/desktop/src/renderer/routes/_authenticated/settings/components/BranchPrefixControl/BranchPrefixControl.tsx
  • apps/desktop/src/renderer/routes/_authenticated/settings/git/components/GitSettings/GitSettings.tsx
  • apps/desktop/src/renderer/routes/_authenticated/settings/project/$projectId/components/ProjectSettings/ProjectSettings.tsx
  • packages/shared/src/workspace-launch/branch.ts

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 5 files

Architecture diagram
sequenceDiagram
    participant UI as Settings UI (BranchPrefixControl / GitSettings / ProjectSettings)
    participant Shared as @superset/shared/workspace-launch
    participant TRPC as TRPC Router (branch-prefix.ts)
    participant GitUtils as Git Utilities (git.ts)
    participant DB as Database

    Note over UI,DB: Custom Branch Prefix Flow

    UI->>UI: User types prefix (e.g. "user/my-name")
    UI->>UI: handleCustomPrefixBlur()
    UI->>Shared: sanitizeBranchName(input)
    Shared-->>UI: sanitized prefix with slashes preserved
    alt prefix is non-empty
        UI->>TRPC: setBranchPrefix.mutate({ mode: "custom", customPrefix })
    else prefix is empty
        UI->>TRPC: setBranchPrefix.mutate({ mode: "custom", customPrefix: null })
    end

    Note over UI,DB: Branch Resolution (on workspace create)

    TRPC->>Shared: resolveBranchPrefix({ mode: "custom", customPrefix })
    alt mode is "custom" and prefix is non-empty
        Shared->>Shared: sanitizeBranchNameWithMaxLength(prefix, 50, { preserveCase: true })
        Shared-->>TRPC: sanitized prefix with slashes
    else mode is "custom" and prefix is null/empty
        Shared-->>TRPC: null
    else mode is "author"
        TRPC->>GitUtils: sanitizeAuthorPrefix(rawPrefix)
        GitUtils-->>TRPC: author prefix (no slashes)
    end
    TRPC->>GitUtils: getBranchPrefix() for collision check
    GitUtils-->>TRPC: existing branch names
    TRPC->>DB: Check prefix collision
    DB-->>TRPC: collision result
    TRPC-->>UI: resolved branch prefix with slashes

    Note over UI,DB: Previously saved prefixes that lost slashes stay mangled
Loading

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@prayagtushar
prayagtushar force-pushed the fix/branch-prefix-slashes branch from 2a8044b to 9bc85cf Compare August 5, 2026 11:12
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@apps/desktop/src/renderer/routes/_authenticated/settings/git/components/GitSettings/GitSettings.tsx`:
- Around line 103-106: Update the custom prefix handling in GitSettings to call
sanitizeBranchName with the segment-length cap rather than the total branch-name
cap, allowing the full prefix through. Keep the final truncateBranchName call
responsible for the total branch-name limit and retain its segment-length
argument so the returned branch name preserves the segment-length contract.

In `@packages/shared/src/workspace-launch/branch.ts`:
- Around line 202-208: Update the custom-prefix return logic in the branch
resolver to normalize a sanitizer result of an empty string to null. Preserve
the existing null result for absent customPrefix and the sanitized value for
non-empty results, matching the desktop resolver’s behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3ffea560-af7a-4d51-8a7c-668271001eb1

📥 Commits

Reviewing files that changed from the base of the PR and between 34a6160 and 9bc85cf.

📒 Files selected for processing (6)
  • apps/desktop/src/lib/trpc/routers/workspaces/utils/branch-prefix.ts
  • apps/desktop/src/renderer/routes/_authenticated/settings/components/BranchPrefixControl/BranchPrefixControl.tsx
  • apps/desktop/src/renderer/routes/_authenticated/settings/git/components/GitSettings/GitSettings.tsx
  • apps/desktop/src/renderer/routes/_authenticated/settings/project/$projectId/components/ProjectSettings/ProjectSettings.tsx
  • packages/host-service/src/trpc/router/workspace-creation/utils/branch-prefix.ts
  • packages/shared/src/workspace-launch/branch.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • apps/desktop/src/renderer/routes/_authenticated/settings/project/$projectId/components/ProjectSettings/ProjectSettings.tsx
  • apps/desktop/src/renderer/routes/_authenticated/settings/components/BranchPrefixControl/BranchPrefixControl.tsx
  • apps/desktop/src/lib/trpc/routers/workspaces/utils/branch-prefix.ts

@prayagtushar
prayagtushar force-pushed the fix/branch-prefix-slashes branch from 4175e61 to f5bdf64 Compare August 5, 2026 14:35
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/shared/src/workspace-launch/branch.ts`:
- Around line 192-197: Update sanitizeCustomBranchPrefix in
packages/shared/src/workspace-launch/branch.ts (lines 192-197) to sanitize each
slash-delimited segment with DEFAULT_BRANCH_SEGMENT_MAX_LENGTH, remove empty
segments, and join the results with “/”. Update the expectation in
packages/shared/src/workspace-launch/branch.test.ts (lines 223-230) to require
the full user/ prefix plus a 50-character final segment.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 1fa48ded-f8f5-4045-acec-4ae7b484a738

📥 Commits

Reviewing files that changed from the base of the PR and between 34a6160 and f5bdf64.

📒 Files selected for processing (7)
  • apps/desktop/src/lib/trpc/routers/workspaces/utils/branch-prefix.ts
  • apps/desktop/src/renderer/routes/_authenticated/settings/components/BranchPrefixControl/BranchPrefixControl.tsx
  • apps/desktop/src/renderer/routes/_authenticated/settings/git/components/GitSettings/GitSettings.tsx
  • apps/desktop/src/renderer/routes/_authenticated/settings/project/$projectId/components/ProjectSettings/ProjectSettings.tsx
  • packages/host-service/src/trpc/router/workspace-creation/utils/branch-prefix.ts
  • packages/shared/src/workspace-launch/branch.test.ts
  • packages/shared/src/workspace-launch/branch.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • apps/desktop/src/renderer/routes/_authenticated/settings/project/$projectId/components/ProjectSettings/ProjectSettings.tsx
  • apps/desktop/src/renderer/routes/_authenticated/settings/components/BranchPrefixControl/BranchPrefixControl.tsx
  • apps/desktop/src/lib/trpc/routers/workspaces/utils/branch-prefix.ts
  • apps/desktop/src/renderer/routes/_authenticated/settings/git/components/GitSettings/GitSettings.tsx
  • packages/host-service/src/trpc/router/workspace-creation/utils/branch-prefix.ts

@prayagtushar
prayagtushar force-pushed the fix/branch-prefix-slashes branch from f5bdf64 to aebba84 Compare August 5, 2026 18:32
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@github-actions

Copy link
Copy Markdown
Contributor

This PR has had no activity for 53 days and will close in 7 days unless there is new activity. If this contribution is still important or relevant, please leave a comment to keep it open. If it closes, you are welcome to reopen it or ask a maintainer to reopen it. Thank you for contributing!

@github-actions github-actions Bot added the stale label Sep 29, 2026

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Branch prefixes can't include slashes ("/")

1 participant