Repository navigation
fix(shared,desktop): allow slashes in custom branch prefixes - #6151
prayagtushar wants to merge 1 commit into
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughCustom 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. ChangesBranch prefix handling
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Greptile SummaryThe 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.
Confidence Score: 4/5The 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
|
| 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]
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
There was a problem hiding this comment.
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
📒 Files selected for processing (5)
apps/desktop/src/lib/trpc/routers/workspaces/utils/branch-prefix.tsapps/desktop/src/renderer/routes/_authenticated/settings/components/BranchPrefixControl/BranchPrefixControl.tsxapps/desktop/src/renderer/routes/_authenticated/settings/git/components/GitSettings/GitSettings.tsxapps/desktop/src/renderer/routes/_authenticated/settings/project/$projectId/components/ProjectSettings/ProjectSettings.tsxpackages/shared/src/workspace-launch/branch.ts
There was a problem hiding this comment.
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
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
2a8044b to
9bc85cf
Compare
|
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. |
There was a problem hiding this comment.
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
📒 Files selected for processing (6)
apps/desktop/src/lib/trpc/routers/workspaces/utils/branch-prefix.tsapps/desktop/src/renderer/routes/_authenticated/settings/components/BranchPrefixControl/BranchPrefixControl.tsxapps/desktop/src/renderer/routes/_authenticated/settings/git/components/GitSettings/GitSettings.tsxapps/desktop/src/renderer/routes/_authenticated/settings/project/$projectId/components/ProjectSettings/ProjectSettings.tsxpackages/host-service/src/trpc/router/workspace-creation/utils/branch-prefix.tspackages/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
4175e61 to
f5bdf64
Compare
|
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. |
There was a problem hiding this comment.
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
📒 Files selected for processing (7)
apps/desktop/src/lib/trpc/routers/workspaces/utils/branch-prefix.tsapps/desktop/src/renderer/routes/_authenticated/settings/components/BranchPrefixControl/BranchPrefixControl.tsxapps/desktop/src/renderer/routes/_authenticated/settings/git/components/GitSettings/GitSettings.tsxapps/desktop/src/renderer/routes/_authenticated/settings/project/$projectId/components/ProjectSettings/ProjectSettings.tsxpackages/host-service/src/trpc/router/workspace-creation/utils/branch-prefix.tspackages/shared/src/workspace-launch/branch.test.tspackages/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
f5bdf64 to
aebba84
Compare
|
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. |
|
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! |
What & why
fixes #5367
The custom branch prefix ran through
sanitizeSegment, which strips/, souser/my-namewas saved asusermy-name.It now uses
sanitizeBranchName, which cleans each segment and keeps theslashes. 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:usermy-name, previewusermy-name/branch-nameuser/my-name, previewuser/my-name/branch-nameCreated a workspace and got
user/my-name/<slug>.Checklist
type(scope): subject)bun run lintbun run typecheckfails in@superset/uiSummary 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
host-service.Migration
Written for commit aebba84. Summary will update on new commits.
Summary by CodeRabbit