feat: new branches use the shorter t3/ prefix (#16220)
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
1 parent
cbb731beb3
commit
2afe87ea4b
9 files changed
+59
-53
No files matched your search
@@ -190,34 +190,37 @@ describe("isTemporaryWorktreeBranch", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("matches legacy UUID-shaped temporary worktree refs from older mobile builds", () => {
|
||||
it("matches legacy t3code temporary worktree refs", () => {
|
||||
expect(isTemporaryWorktreeBranch("t3code/deadbeef")).toBe(true);
|
||||
expect(isTemporaryWorktreeBranch("t3code-deadbeef")).toBe(true);
|
||||
expect(isTemporaryWorktreeBranch("t3code/f4ae4e0e-f971-4d48-b4f2-9cf0aa54ab12")).toBe(true);
|
||||
expect(
|
||||
isTemporaryWorktreeBranch(`${WORKTREE_BRANCH_PREFIX}/f4ae4e0e-f971-4d48-b4f2-9cf0aa54ab12`),
|
||||
).toBe(true);
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("rejects UUID-shaped refs that are not RFC 4122 v4", () => {
|
||||
// version nibble is not 4
|
||||
expect(
|
||||
isTemporaryWorktreeBranch(`${WORKTREE_BRANCH_PREFIX}/f4ae4e0e-f971-1d48-b4f2-9cf0aa54ab12`),
|
||||
).toBe(false);
|
||||
expect(isTemporaryWorktreeBranch("t3code/f4ae4e0e-f971-1d48-b4f2-9cf0aa54ab12")).toBe(false);
|
||||
// variant nibble is not [89ab]
|
||||
expect(
|
||||
isTemporaryWorktreeBranch(`${WORKTREE_BRANCH_PREFIX}/f4ae4e0e-f971-4d48-c4f2-9cf0aa54ab12`),
|
||||
).toBe(false);
|
||||
expect(isTemporaryWorktreeBranch("t3code/f4ae4e0e-f971-4d48-c4f2-9cf0aa54ab12")).toBe(false);
|
||||
});
|
||||
|
||||
it("matches the flat fallback used when a plain t3code branch exists", () => {
|
||||
it("matches the flat fallback used when a plain t3 branch exists", () => {
|
||||
const flat = flattenTemporaryWorktreeBranchName(`${WORKTREE_BRANCH_PREFIX}/deadbeef`);
|
||||
expect(flat).toBe(`${WORKTREE_BRANCH_PREFIX}-deadbeef`);
|
||||
expect(isTemporaryWorktreeBranch(flat)).toBe(true);
|
||||
expect(isTemporaryWorktreeBranch(`${WORKTREE_BRANCH_PREFIX}-deadbeef-extra`)).toBe(false);
|
||||
expect(isTemporaryWorktreeBranch(`${WORKTREE_BRANCH_PREFIX}-feature`)).toBe(false);
|
||||
expect(
|
||||
flattenTemporaryWorktreeBranchName(
|
||||
`${WORKTREE_BRANCH_PREFIX}/f4ae4e0e-f971-4d48-b4f2-9cf0aa54ab12`,
|
||||
),
|
||||
).toBe(`${WORKTREE_BRANCH_PREFIX}-f4ae4e0e`);
|
||||
expect(flattenTemporaryWorktreeBranchName("t3code/f4ae4e0e-f971-4d48-b4f2-9cf0aa54ab12")).toBe(
|
||||
`${WORKTREE_BRANCH_PREFIX}-f4ae4e0e`,
|
||||
);
|
||||
expect(flattenTemporaryWorktreeBranchName("t3code-deadbeef")).toBe(
|
||||
`${WORKTREE_BRANCH_PREFIX}-deadbeef`,
|
||||
);
|
||||
expect(flattenTemporaryWorktreeBranchName("t3code/deadbeef")).toBe(
|
||||
`${WORKTREE_BRANCH_PREFIX}-deadbeef`,
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects non-temporary refName names", () => {
|
||||
|
||||
+17
-14
@@ -11,14 +11,18 @@ import * as Arr from "effect/Array";
|
||||
import * as Result from "effect/Result";
|
||||
import { detectSourceControlProviderFromRemoteUrl } from "./sourceControl.ts";
|
||||
|
||||
export const WORKTREE_BRANCH_PREFIX = "t3code";
|
||||
// Canonical form is `t3code/<8 hex>`. Older mobile builds generated `t3code/<uuid>`
|
||||
// via Crypto.randomUUID() (always RFC 4122 v4), so the matcher also accepts exactly
|
||||
// that shape — version nibble `4`, variant nibble `[89ab]` — to keep those threads
|
||||
// eligible for branch regeneration without loosening beyond what was ever generated.
|
||||
// `t3code-<8 hex>` is the fallback when a plain `t3code` branch blocks the namespace.
|
||||
export const WORKTREE_BRANCH_PREFIX = "t3";
|
||||
// Canonical form is `t3/<8 hex>`. `t3-<8 hex>` is the fallback when a plain `t3`
|
||||
// branch blocks the namespace. The matcher also accepts every legacy shape, so
|
||||
// existing threads stay eligible for branch regeneration: `t3code/<8 hex>` and
|
||||
// `t3code-<8 hex>` from before the prefix was shortened, and `t3code/<uuid>` from
|
||||
// older mobile builds that used Crypto.randomUUID() (always RFC 4122 v4, so version
|
||||
// nibble `4` and variant nibble `[89ab]`). Nothing looser than what was generated.
|
||||
const TEMP_WORKTREE_HEX_TOKEN = "[0-9a-f]{8}";
|
||||
const TEMP_WORKTREE_UUID_V4_TOKEN =
|
||||
"[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}";
|
||||
const TEMP_WORKTREE_BRANCH_PATTERN = new RegExp(
|
||||
`^${WORKTREE_BRANCH_PREFIX}(?:-[0-9a-f]{8}$|\\/(?:[0-9a-f]{8}|[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})$)`,
|
||||
`^(?:${WORKTREE_BRANCH_PREFIX}[-/]${TEMP_WORKTREE_HEX_TOKEN}|t3code(?:[-/]${TEMP_WORKTREE_HEX_TOKEN}|\\/${TEMP_WORKTREE_UUID_V4_TOKEN}))$`,
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -125,15 +129,14 @@ export function buildTemporaryWorktreeBranchName(
|
||||
}
|
||||
|
||||
/**
|
||||
* Git stores refs as paths, so a plain `t3code` branch makes every `t3code/<hex>`
|
||||
* ref impossible. This moves a temporary name to the flat `t3code-<hex>` sibling.
|
||||
* Git stores refs as paths, so a plain `t3` branch makes every `t3/<hex>`
|
||||
* ref impossible. This moves a temporary name to the flat `t3-<hex>` sibling.
|
||||
*/
|
||||
export function flattenTemporaryWorktreeBranchName(refName: string): string {
|
||||
// Keep only the canonical 8-hex token so legacy UUID names stay recognizable.
|
||||
const token = refName
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.slice(WORKTREE_BRANCH_PREFIX.length + 1, WORKTREE_BRANCH_PREFIX.length + 9);
|
||||
// Keep only the canonical 8-hex token so legacy `t3code/` and UUID names map cleanly.
|
||||
const normalized = refName.trim().toLowerCase();
|
||||
const tokenStart = normalized.search(/[-/]/) + 1;
|
||||
const token = normalized.slice(tokenStart, tokenStart + 8);
|
||||
return `${WORKTREE_BRANCH_PREFIX}-${token}`;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user