Skip to content

Commit e8d3a06

Browse files
Unify temporary worktree branch naming
- Normalize generated names to the canonical 8-hex format - Accept legacy UUID-shaped mobile branch names - Add regression coverage for both behaviors
1 parent 32c6012 commit e8d3a06

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

‎packages/shared/src/git.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ describe("isTemporaryWorktreeBranch", () => {
7171
expect(isTemporaryWorktreeBranch(`${WORKTREE_BRANCH_PREFIX}/DEADBEEF`)).toBe(true);
7272
});
7373

74+
it("normalizes a UUID-shaped random callback to the canonical 8-hex form", () => {
75+
expect(buildTemporaryWorktreeBranchName(() => "f4ae4e0e-f971-4d48-b4f2-9cf0aa54ab12")).toBe(
76+
`${WORKTREE_BRANCH_PREFIX}/f4ae4e0e`,
77+
);
78+
});
79+
80+
it("matches legacy UUID-shaped temporary worktree refs from older mobile builds", () => {
81+
expect(
82+
isTemporaryWorktreeBranch(`${WORKTREE_BRANCH_PREFIX}/f4ae4e0e-f971-4d48-b4f2-9cf0aa54ab12`),
83+
).toBe(true);
84+
});
85+
7486
it("rejects non-temporary refName names", () => {
7587
expect(isTemporaryWorktreeBranch(`${WORKTREE_BRANCH_PREFIX}/feature/demo`)).toBe(false);
7688
expect(isTemporaryWorktreeBranch("main")).toBe(false);

‎packages/shared/src/git.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import * as Result from "effect/Result";
1111
import { detectSourceControlProviderFromRemoteUrl } from "./sourceControl.ts";
1212

1313
export const WORKTREE_BRANCH_PREFIX = "t3code";
14-
const TEMP_WORKTREE_BRANCH_PATTERN = new RegExp(`^${WORKTREE_BRANCH_PREFIX}\\/[0-9a-f]{8}$`);
14+
// Canonical form is `t3code/<8 hex>`. Older mobile builds generated `t3code/<uuid>`,
15+
// so the matcher accepts both to keep those threads eligible for branch regeneration.
16+
const TEMP_WORKTREE_BRANCH_PATTERN = new RegExp(
17+
`^${WORKTREE_BRANCH_PREFIX}\\/(?:[0-9a-f]{8}|[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$`,
18+
);
1519

1620
/**
1721
* Sanitize an arbitrary string into a valid, lowercase git refName fragment.
@@ -89,7 +93,12 @@ export function deriveLocalBranchNameFromRemoteRef(branchName: string): string {
8993
export function buildTemporaryWorktreeBranchName(
9094
randomHex: (byteLength: number) => string,
9195
): string {
92-
const token = randomHex(4).toLowerCase();
96+
// Normalize to exactly 8 lowercase hex chars so a UUID-shaped callback
97+
// still produces the canonical temporary branch form.
98+
const token = randomHex(4)
99+
.toLowerCase()
100+
.replace(/[^0-9a-f]/g, "")
101+
.slice(0, 8);
93102
return `${WORKTREE_BRANCH_PREFIX}/${token}`;
94103
}
95104

0 commit comments

Comments
 (0)