Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions scripts/bash/create-new-feature.sh
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,11 @@ if [ "$DRY_RUN" != true ]; then

if [ "$NEEDS_SPEC" = true ]; then
if [ "$SPEC_TEMPLATE_FOUND" = true ]; then
# Fill the literal [DATE] placeholder with today's local date (#4335).
# Parameter expansion keeps the template text literal; the escaped
# brackets match only the exact token.
SPEC_TODAY=$(date +%Y-%m-%d)
SPEC_TEMPLATE_CONTENT=${SPEC_TEMPLATE_CONTENT//\[DATE\]/$SPEC_TODAY}
printf '%s' "$SPEC_TEMPLATE_CONTENT" > "$SPEC_FILE"
else
echo "Warning: Spec template not found; created empty spec file" >&2
Expand Down
9 changes: 8 additions & 1 deletion scripts/bash/setup-plan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ else
echo "Restore a valid plan template and rerun plan setup." >&2
exit 1
fi
cat "$template_file" > "$IMPL_PLAN"
# Fill the literal [DATE] placeholder with today's local date (#4335).
# The sentinel keeps trailing newlines; parameter expansion keeps the
# template text literal and the escaped brackets match only the token.
plan_content=$(cat "$template_file"; printf x)
plan_content=${plan_content%x}
plan_today=$(date +%Y-%m-%d)
plan_content=${plan_content//\[DATE\]/$plan_today}
printf '%s' "$plan_content" > "$IMPL_PLAN"
if $JSON_MODE; then
echo "Copied plan template to $IMPL_PLAN" >&2
else
Expand Down
4 changes: 4 additions & 0 deletions scripts/powershell/create-new-feature.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ if (-not $DryRun) {

if ($needsSpec) {
if ($null -ne $content) {
# Fill the literal [DATE] placeholder with today's local date (#4335).
# String.Replace is ordinal and literal (no regex, no expansion).
$today = (Get-Date).ToString('yyyy-MM-dd', [System.Globalization.CultureInfo]::InvariantCulture)
$content = $content.Replace('[DATE]', $today)
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
[System.IO.File]::WriteAllText($specFile, $content, $utf8NoBom)
} else {
Expand Down
4 changes: 4 additions & 0 deletions scripts/powershell/setup-plan.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ if (Test-Path -LiteralPath $paths.IMPL_PLAN -PathType Leaf) {
[Console]::Error.WriteLine("Restore a valid plan template and rerun plan setup.")
exit 1
}
# Fill the literal [DATE] placeholder with today's local date (#4335).
# String.Replace is ordinal and literal (no regex, no expansion).
$today = (Get-Date).ToString('yyyy-MM-dd', [System.Globalization.CultureInfo]::InvariantCulture)
$content = $content.Replace('[DATE]', $today)
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
[System.IO.File]::WriteAllText($paths.IMPL_PLAN, $content, $utf8NoBom)
# Emit the copy status like the bash twin (setup-plan.sh); route to stderr
Expand Down
4 changes: 4 additions & 0 deletions scripts/python/create_new_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@ def main(argv: list[str] | None = None) -> int:

if needs_spec:
if template_content is not None:
# Fill the literal [DATE] placeholder with today's local date (#4335).
template_content = template_content.replace(
"[DATE]", datetime.date.today().isoformat()
)
spec_file.write_bytes(template_content.encode("utf-8"))
else:
print(
Expand Down
5 changes: 5 additions & 0 deletions scripts/python/setup_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from __future__ import annotations

import datetime
import json
import sys
from pathlib import Path
Expand Down Expand Up @@ -81,6 +82,10 @@ def main(argv: list[str] | None = None) -> int:
file=sys.stderr,
)
return 1
# Fill the literal [DATE] placeholder with today's local date (#4335).
template_content = template_content.replace(
"[DATE]", datetime.date.today().isoformat()
)
paths.impl_plan.write_bytes(template_content.encode("utf-8"))
print(f"Copied plan template to {paths.impl_plan}", file=status_stream)
else:
Expand Down
9 changes: 8 additions & 1 deletion tests/test_setup_plan_no_overwrite.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Tests for setup-plan preserving existing plan.md (#2653)."""

import datetime
import json
import os
import shutil
Expand Down Expand Up @@ -240,6 +241,7 @@ def test_ps_setup_plan_does_not_match_another_features_plan(plan_repo: Path) ->

script = plan_repo / ".specify" / "scripts" / "powershell" / "setup-plan.ps1"
exe = "pwsh" if HAS_PWSH else _WINDOWS_POWERSHELL
before = datetime.date.today().isoformat()
result = subprocess.run(
[exe, "-NoProfile", "-File", str(script), "-Json"],
cwd=plan_repo,
Expand All @@ -248,11 +250,16 @@ def test_ps_setup_plan_does_not_match_another_features_plan(plan_repo: Path) ->
check=False,
env=_clean_env(),
)
after = datetime.date.today().isoformat()
assert result.returncode == 0, result.stderr
data = json.loads(result.stdout)
plan_path = plan_repo / "specs" / feature_name / "plan.md"
assert Path(data["IMPL_PLAN"]) == plan_path
assert plan_path.read_text(encoding="utf-8") == PLAN_TEMPLATE.read_text(encoding="utf-8")
# setup-plan fills the template's [DATE] placeholder with today's date (#4335).
template = PLAN_TEMPLATE.read_text(encoding="utf-8")
assert plan_path.read_text(encoding="utf-8") in {
template.replace("[DATE]", day) for day in (before, after)
}
assert (neighbor / "plan.md").read_text(encoding="utf-8") == existing_content
assert "Copied plan template" in result.stderr

Expand Down
Loading
Loading