From ed23fe56ab7412a6b426af4e51bafce3155d0347 Mon Sep 17 00:00:00 2001 From: Lex Christopherson Date: Wed, 25 Mar 2026 22:39:52 -0600 Subject: [PATCH] refactor: consolidate branch name patterns into single module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SLICE_BRANCH_RE, QUICK_BRANCH_RE, and WORKFLOW_BRANCH_RE were scattered across worktree.ts and git-service.ts. Extract all three into branch-patterns.ts as the single source of truth. Both original modules re-export for backward compatibility — no consumer changes needed. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/resources/extensions/gsd/branch-patterns.ts | 16 ++++++++++++++++ src/resources/extensions/gsd/git-service.ts | 15 +++------------ src/resources/extensions/gsd/worktree.ts | 5 +++-- 3 files changed, 22 insertions(+), 14 deletions(-) create mode 100644 src/resources/extensions/gsd/branch-patterns.ts diff --git a/src/resources/extensions/gsd/branch-patterns.ts b/src/resources/extensions/gsd/branch-patterns.ts new file mode 100644 index 000000000..70d8a40ab --- /dev/null +++ b/src/resources/extensions/gsd/branch-patterns.ts @@ -0,0 +1,16 @@ +/** + * GSD branch naming patterns — single source of truth. + * + * gsd/// → SLICE_BRANCH_RE + * gsd/quick/- → QUICK_BRANCH_RE + * gsd//<...> → WORKFLOW_BRANCH_RE (non-milestone gsd/ branches) + */ + +/** Matches gsd/ slice branches: gsd/[worktree/]M001[-hash]/S01 */ +export const SLICE_BRANCH_RE = /^gsd\/(?:([a-zA-Z0-9_-]+)\/)?(M\d+(?:-[a-z0-9]{6})?)\/(S\d+)$/; + +/** Matches gsd/quick/ task branches */ +export const QUICK_BRANCH_RE = /^gsd\/quick\//; + +/** Matches gsd/ workflow branches (non-milestone, e.g. gsd/workflow-name/...) */ +export const WORKFLOW_BRANCH_RE = /^gsd\/(?!M\d)[\w-]+\//; diff --git a/src/resources/extensions/gsd/git-service.ts b/src/resources/extensions/gsd/git-service.ts index 69851c418..1d84ae3d6 100644 --- a/src/resources/extensions/gsd/git-service.ts +++ b/src/resources/extensions/gsd/git-service.ts @@ -18,8 +18,8 @@ import { loadEffectiveGSDPreferences } from "./preferences.js"; import { detectWorktreeName, - SLICE_BRANCH_RE, } from "./worktree.js"; +import { SLICE_BRANCH_RE, QUICK_BRANCH_RE, WORKFLOW_BRANCH_RE } from "./branch-patterns.js"; import { nativeGetCurrentBranch, nativeDetectMainBranch, @@ -243,17 +243,8 @@ export function readIntegrationBranch(basePath: string, milestoneId: string): st * * The file is committed immediately so the metadata is persisted in git. */ -/** Regex matching GSD quick-task branches: gsd/quick/- */ -export const QUICK_BRANCH_RE = /^gsd\/quick\//; - -/** - * Matches all GSD workflow-template branches: gsd//. - * - * Template IDs are lowercase alphanumeric with hyphens (e.g. hotfix, bugfix, - * small-feature, dep-upgrade). The negative lookahead excludes milestone - * branches (gsd/M001/... or gsd/M001-abc123/...) which use SLICE_BRANCH_RE. - */ -export const WORKFLOW_BRANCH_RE = /^gsd\/(?!M\d)[\w-]+\//; +/** Re-export for backward compatibility — canonical definitions in branch-patterns.ts */ +export { QUICK_BRANCH_RE, WORKFLOW_BRANCH_RE } from "./branch-patterns.js"; export function writeIntegrationBranch( basePath: string, diff --git a/src/resources/extensions/gsd/worktree.ts b/src/resources/extensions/gsd/worktree.ts index 84d3dd6d2..0f84166ae 100644 --- a/src/resources/extensions/gsd/worktree.ts +++ b/src/resources/extensions/gsd/worktree.ts @@ -235,8 +235,9 @@ export function getSliceBranchName(milestoneId: string, sliceId: string, worktre return `gsd/${milestoneId}/${sliceId}`; } -/** Regex that matches both plain and worktree-namespaced slice branches. */ -export const SLICE_BRANCH_RE = /^gsd\/(?:([a-zA-Z0-9_-]+)\/)?(M\d+(?:-[a-z0-9]{6})?)\/(S\d+)$/; +/** Re-export for backward compatibility — canonical definition in branch-patterns.ts */ +export { SLICE_BRANCH_RE } from "./branch-patterns.js"; +import { SLICE_BRANCH_RE } from "./branch-patterns.js"; /** * Parse a slice branch name into its components.