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

PR
2mo ago
+176-14

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.

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.