fix(settings): normalize and validate branch prefixes (#7772)
* Normalize branch prefixes and flag invalid ones in settings A custom branch prefix ending in a slash (e.g. "team/") produced a double-slashed branch name like "team//feature" that git rejects, and the raw check-ref-format error gave no hint that the prefix caused it. - Normalize the configured prefix (trim whitespace, strip leading/ trailing and duplicate slashes) in the shared branch-name builder so the common trailing-slash case just works, for local and SSH worktrees. - Validate the prefix on the worktree-create path (computeValidatedBranchName) so a genuinely invalid prefix fails fast with a clear "update it in Settings -> Git" message instead of an opaque git error. - Add a live BranchPrefixFeedback under the Branch Prefix setting: previews the resulting branch name, warns on invalid characters, and notes when a prefix collapses to none. - Keep the background first-work rename on the non-throwing builder since the prefix is already validated at create time. * Keep caret in place when editing the branch prefix The custom branch prefix input was directly controlled by settings, but updateSettings persists through an async IPC round-trip, so the value updated a tick late and React re-assigned it, snapping the caret to the end on mid-string edits. Drive the input from a local draft and only adopt genuine external settings changes so the caret stays put (and fast typing survives slow SSH round-trips). Co-authored-by: Cursor <cursoragent@cursor.com> * Return ReactNode from BranchPrefixFeedback JSX.Element needlessly excludes null/string/number returns; ReactNode keeps the component's return type from over-constraining future changes. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -112,6 +112,7 @@ import type {
|
||||
ForceDeleteWorktreeBranchResult,
|
||||
GitHubPrStartPoint,
|
||||
GitPushTarget,
|
||||
BranchPrefixStrategy,
|
||||
GitWorktreeInfo,
|
||||
GitHubCreateIssueFields,
|
||||
GitHubOwnerRepo,
|
||||
@@ -796,7 +797,7 @@ import type { Store } from '../persistence'
|
||||
import type { StatsCollector } from '../stats/collector'
|
||||
import { AgentDetector } from '../stats/agent-detector'
|
||||
import {
|
||||
computeBranchName,
|
||||
computeValidatedBranchName,
|
||||
computeWorktreePath,
|
||||
computeWorkspaceRoot,
|
||||
ensurePathWithinWorkspace,
|
||||
@@ -1886,7 +1887,13 @@ async function resolveCreateBranchName(
|
||||
gitOptions: { wslDistro?: string } = {}
|
||||
): Promise<string> {
|
||||
if (!branchNameOverride) {
|
||||
return computeBranchName(sanitizedName, settings, username)
|
||||
// The runtime store's getSettings() types branchPrefix loosely as string;
|
||||
// it is always one of the BranchPrefixStrategy literals at runtime.
|
||||
return computeValidatedBranchName(
|
||||
sanitizedName,
|
||||
{ ...settings, branchPrefix: settings.branchPrefix as BranchPrefixStrategy },
|
||||
username
|
||||
)
|
||||
}
|
||||
if (branchNameOverride.startsWith('-')) {
|
||||
throw new Error('Branch name must not start with "-"')
|
||||
|
||||
Reference in New Issue
Block a user