Skip to content

Commit a74b8e7

Browse files
t-sakodaclaude
andcommitted
fix: reject timestamp-like branches without trailing slug
Branches like "20260319-143022" (no "-<name>" suffix) were incorrectly accepted as sequential prefixes. Add explicit rejection for 7-or-8 digit date + 6-digit time patterns with no trailing slug, in both common.sh and common.ps1. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 49c29c2 commit a74b8e7

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

scripts/bash/common.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,10 @@ check_feature_branch() {
124124
return 0
125125
fi
126126

127-
# Accept sequential prefix (3+ digits) but exclude malformed timestamps (7-digit date + 6-digit time)
127+
# Accept sequential prefix (3+ digits) but exclude malformed timestamps
128+
# Malformed: 7-or-8 digit date + 6-digit time with no trailing slug (e.g. "2026031-143022" or "20260319-143022")
128129
local is_sequential=false
129-
if [[ "$branch" =~ ^[0-9]{3,}- ]] && [[ ! "$branch" =~ ^[0-9]{7}-[0-9]{6}- ]]; then
130+
if [[ "$branch" =~ ^[0-9]{3,}- ]] && [[ ! "$branch" =~ ^[0-9]{7}-[0-9]{6}- ]] && [[ ! "$branch" =~ ^[0-9]{7,8}-[0-9]{6}$ ]]; then
130131
is_sequential=true
131132
fi
132133
if [[ "$is_sequential" != "true" ]] && [[ ! "$branch" =~ ^[0-9]{8}-[0-9]{6}- ]]; then

scripts/powershell/common.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,10 @@ function Test-FeatureBranch {
139139
return $true
140140
}
141141

142-
# Accept sequential prefix (3+ digits) but exclude malformed timestamps (7-digit date + 6-digit time)
143-
$isSequential = ($Branch -match '^[0-9]{3,}-') -and ($Branch -notmatch '^[0-9]{7}-[0-9]{6}-')
142+
# Accept sequential prefix (3+ digits) but exclude malformed timestamps
143+
# Malformed: 7-or-8 digit date + 6-digit time with no trailing slug (e.g. "2026031-143022" or "20260319-143022")
144+
$hasMalformedTimestamp = ($Branch -match '^[0-9]{7}-[0-9]{6}-') -or ($Branch -match '^(?:\d{7}|\d{8})-\d{6}$')
145+
$isSequential = ($Branch -match '^[0-9]{3,}-') -and (-not $hasMalformedTimestamp)
144146
if (-not $isSequential -and $Branch -notmatch '^\d{8}-\d{6}-') {
145147
Write-Output "ERROR: Not on a feature branch. Current branch: $Branch"
146148
Write-Output "Feature branches should be named like: 001-feature-name, 1234-feature-name, or 20260319-143022-feature-name"

tests/test_timestamp_branches.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ def test_rejects_partial_timestamp(self):
196196
result = source_and_call('check_feature_branch "2026031-143022-feat" "true"')
197197
assert result.returncode != 0
198198

199+
def test_rejects_timestamp_without_slug(self):
200+
"""check_feature_branch rejects timestamp-like branch missing trailing slug."""
201+
result = source_and_call('check_feature_branch "20260319-143022" "true"')
202+
assert result.returncode != 0
203+
204+
def test_rejects_7digit_timestamp_without_slug(self):
205+
"""check_feature_branch rejects 7-digit date + 6-digit time without slug."""
206+
result = source_and_call('check_feature_branch "2026031-143022" "true"')
207+
assert result.returncode != 0
208+
199209

200210
# ── find_feature_dir_by_prefix Tests ─────────────────────────────────────────
201211

0 commit comments

Comments
 (0)