Skip to content

fix: prevent trailing slash in branch prefixes#2202

Merged
arnestrickmann merged 2 commits into
mainfrom
cursor/05ea18d5
May 24, 2026
Merged

fix: prevent trailing slash in branch prefixes#2202
arnestrickmann merged 2 commits into
mainfrom
cursor/05ea18d5

Conversation

@janburzinski
Copy link
Copy Markdown
Collaborator

summary

  • prevent branch prefixes from ending with "/" to avoid double invalid generated branch names liek emdash//name
  • normalize or validate configured branch prefix

Extract normalizeBranchPrefix into a shared utility and apply it as a
zod transform on the branchPrefix schema, removing the manual .trim()
from the renderer component.
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 23, 2026

Greptile Summary

This PR introduces a normalizeBranchPrefix utility that strips leading/trailing slashes and whitespace from branch prefixes, preventing double-slash refs like prefix//branch-name. The normalization is applied both at the schema layer (via Zod .transform) and at the UI layer (on input blur).

  • Adds src/shared/branch-prefix.ts with a single normalizeBranchPrefix function and comprehensive unit tests covering leading/trailing slashes, multi-slash runs, and whitespace.
  • Wires the normalizer into the Zod schema as a .transform so any persisted value is normalized on parse.
  • In RepositorySettingsCard, normalizes on blur and immediately writes e.currentTarget.value = next so the input displays the cleaned value even when it equals the stored value (addressing the stale-display edge case).

Confidence Score: 5/5

Safe to merge — normalization is applied at both the schema and UI layers, and the stale-display edge case from the previous review is fully addressed.

The change is narrowly scoped: a single pure utility function, a Zod transform wired into the existing schema, and a two-line tweak to the blur handler. Both the schema-layer and UI-layer paths correctly normalize the value, the tests cover all meaningful input shapes, and no existing behaviour is altered for already-valid prefixes.

No files require special attention.

Important Files Changed

Filename Overview
src/shared/branch-prefix.ts New utility function that trims whitespace then strips leading/trailing slashes; clean and correct implementation.
src/shared/branch-prefix.test.ts New test file covering trailing slashes, leading slashes, multi-slash runs, whitespace trimming, internal slash preservation, and the empty string case.
src/main/core/settings/schema.ts Adds .transform(normalizeBranchPrefix) to branchPrefix so normalization is enforced on every schema parse; no other changes.
src/renderer/features/settings/components/RepositorySettingsCard.tsx Blur handler now normalizes with normalizeBranchPrefix and immediately updates e.currentTarget.value to keep the displayed value in sync even when normalization doesn't change the stored value.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A([User types branch prefix]) --> B[Input onBlur fires]
    B --> C["normalizeBranchPrefix(e.currentTarget.value)"]
    C --> D["e.currentTarget.value = next\n(display updated immediately)"]
    D --> E{next !== stored branchPrefix?}
    E -- Yes --> F["updateProject({ branchPrefix: next })"]
    F --> G[IPC to main process]
    G --> H["Zod schema: z.string().transform(normalizeBranchPrefix)"]
    H --> I[Normalized value persisted to disk]
    I --> J[State updates, key prop changes, Input remounts]
    E -- No --> K[No IPC call, display already corrected]
Loading

Reviews (2): Last reviewed commit: "fix: address branch prefix review feedba..." | Re-trigger Greptile

Comment thread src/shared/branch-prefix.ts Outdated
@janburzinski
Copy link
Copy Markdown
Collaborator Author

@greptileai

Copy link
Copy Markdown
Contributor

@arnestrickmann arnestrickmann left a comment

Choose a reason for hiding this comment

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

lgtm

@arnestrickmann arnestrickmann merged commit 5bee685 into main May 24, 2026
1 check passed
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.

2 participants