fix: prevent trailing slash in branch prefixes#2202
Conversation
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 SummaryThis PR introduces a
Confidence Score: 5/5Safe 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.
|
| 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]
Reviews (2): Last reviewed commit: "fix: address branch prefix review feedba..." | Re-trigger Greptile
Amp-Thread-ID: https://ampcode.com/threads/T-019e5620-110e-70ee-9385-9159dc625f4f Co-authored-by: Amp <amp@ampcode.com>
summary