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:
Theo BrowneandClaude Opus 5.5 authored and GitHub committed 2026-10-05 15:34:37 -07:00
1 parent cbb731beb3
commit 2afe87ea4b
9 files changed
+59 -53

No files matched your search

+17 -14
View File
@@ -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}`;
}