Skip to content

feat(scripts): add --dry-run flag to create-new-feature#1998

Open
rhuss wants to merge 7 commits intogithub:mainfrom
rhuss:001-dry-run-flag
Open

feat(scripts): add --dry-run flag to create-new-feature#1998
rhuss wants to merge 7 commits intogithub:mainfrom
rhuss:001-dry-run-flag

Conversation

@rhuss
Copy link
Copy Markdown
Contributor

@rhuss rhuss commented Mar 27, 2026

Summary

  • Add --dry-run / -DryRun flag to both bash and PowerShell create-new-feature scripts
  • Computes next branch name, spec file path, and feature number without creating branches, directories, or files
  • Queries remote branches via git ls-remote --heads (read-only) for accurate numbering without mutating local state. This contrasts with the normal (non-dry-run) path which runs git fetch --all --prune to update local remote-tracking refs.
  • JSON output includes DRY_RUN field when flag is active; omitted otherwise (backwards compatible)
  • Enables external tools (e.g., worktree-based workflows) to query the next available name before running the full specify workflow

Closes #1931. Also addresses aspects of #1680, #841, and #1921.

Changes

File Change
scripts/bash/create-new-feature.sh Add --dry-run flag, gate branch/dir creation, add DRY_RUN to JSON, add _extract_highest_number shared helper, add get_highest_from_remote_refs using git ls-remote, add skip_fetch param to check_existing_branches
scripts/powershell/create-new-feature.ps1 Add -DryRun switch, mirror bash logic, add Get-HighestNumberFromNames shared helper, add Get-HighestNumberFromRemoteRefs, add -SkipFetch param to Get-NextBranchNumber
tests/test_timestamp_branches.py Add TestDryRun class (12 tests including remote branch awareness), add TestPowerShellDryRun class (5 tests, skipped without pwsh)

Remote branch handling

Mode How remotes are queried Side effects
Normal (no --dry-run) git fetch --all --prune then git branch -a Updates local remote-tracking refs
--dry-run git ls-remote --heads per remote, plus git branch -a None (read-only query, no local ref updates)

Both modes produce the same numbering result given the same remote state. The difference is that dry-run never modifies .git/refs/remotes/.

Test plan

  • All 18 existing tests pass unchanged (backwards compatibility)
  • 12 new bash dry-run tests cover: sequential numbering, no branch created, no spec dir created, empty repo, short name, dry-run-then-real-run name match, remote branch awareness, JSON field presence/absence, timestamp mode, number flag, non-git repo
  • 5 PowerShell dry-run tests (skipped without pwsh): name output, no branch, no spec dir, JSON field presence/absence
  • Manual smoke test: --dry-run --json outputs correct name with zero side effects

Backwards compatibility

  • Without --dry-run, behavior is 100% unchanged
  • JSON output shape unchanged when --dry-run is not used (no new fields)
  • No new dependencies
  • Refactored shared number extraction helpers reduce code duplication without changing behavior

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings March 27, 2026 17:16
@rhuss rhuss requested a review from mnriem as a code owner March 27, 2026 17:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a --dry-run / -DryRun mode to the create-new-feature scripts so external tooling can compute the next branch/spec identifiers (and optionally JSON output) without performing the normal creation workflow.

Changes:

  • Bash: add --dry-run, skip branch/feature dir/spec file creation when active, and add optional DRY_RUN to JSON output.
  • PowerShell: add -DryRun with equivalent behavior and JSON shaping.
  • Tests: add a TestDryRun suite covering dry-run naming and side-effect expectations (bash).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
scripts/bash/create-new-feature.sh Adds --dry-run, gates creation steps, and conditionally emits DRY_RUN in JSON output.
scripts/powershell/create-new-feature.ps1 Adds -DryRun, mirrors bash dry-run logic, and conditionally emits DRY_RUN in JSON output.
tests/test_timestamp_branches.py Adds dry-run test coverage for naming, JSON field presence/absence, and lack of branch/feature-dir side effects.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Collaborator

@mnriem mnriem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address Copilot feedback. If not applicable, please explain why

rhuss added a commit to rhuss/spec-kit that referenced this pull request Mar 27, 2026
Dry-run was unconditionally creating the root specs/ directory via
mkdir -p / New-Item before the dry-run guard. This violated the
documented contract of zero side effects. Also adds returncode
assertion on git branch --list in tests and adds PowerShell dry-run
test coverage (skipped when pwsh unavailable).

Addresses review comments on github#1998.

Assisted-By: 🤖 Claude Code
@mnriem mnriem requested a review from Copilot March 27, 2026 17:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

rhuss added 3 commits March 28, 2026 06:30
Add a --dry-run / -DryRun flag to both bash and PowerShell
create-new-feature scripts that computes the next branch name,
spec file path, and feature number without creating any branches,
directories, or files. This enables external tools to query the
next available name before running the full specify workflow.

When combined with --json, the output includes a DRY_RUN field.
Without --dry-run, behavior is completely unchanged.

Closes github#1931

Assisted-By: 🤖 Claude Code
Dry-run was unconditionally creating the root specs/ directory via
mkdir -p / New-Item before the dry-run guard. This violated the
documented contract of zero side effects. Also adds returncode
assertion on git branch --list in tests and adds PowerShell dry-run
test coverage (skipped when pwsh unavailable).

Addresses review comments on github#1998.

Assisted-By: 🤖 Claude Code
- Gate `mkdir -p $SPECS_DIR` behind DRY_RUN check (bash + PowerShell)
  so dry-run creates zero directories
- Add returncode assertion on `git branch --list` in test
- Strengthen spec dir test to verify root `specs/` is not created
- Add PowerShell dry-run test class (5 tests, skipped without pwsh)
- Fix run_ps_script to use temp repo copy instead of project root

Assisted-By: 🤖 Claude Code
@rhuss rhuss force-pushed the 001-dry-run-flag branch from c1c467c to ca4f930 Compare March 28, 2026 05:43
Dry-run now queries remote branches via `git ls-remote --heads`
(read-only, no fetch) to account for remote-only branches when
computing the next sequential number. This prevents dry-run from
returning a number that already exists on a remote.

Added test verifying dry-run sees remote-only higher-numbered
branches and adjusts numbering accordingly.

Assisted-By: 🤖 Claude Code
Copilot AI review requested due to automatic review settings March 28, 2026 05:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

rhuss added 2 commits March 28, 2026 07:09
Extract shared _extract_highest_number helper (bash) and
Get-HighestNumberFromNames (PowerShell) to eliminate duplicated
number extraction patterns between local branch and remote ref
scanning.

Add SkipFetch/skip_fetch parameter to check_existing_branches /
Get-NextBranchNumber so dry-run reuses the same function instead
of inlining duplicate max-of-branches-and-specs logic.

Assisted-By: 🤖 Claude Code
Move remote.git and second_clone directories under git_repo
instead of git_repo.parent to prevent path collisions with
parallel test workers.

Assisted-By: 🤖 Claude Code
Copilot AI review requested due to automatic review settings March 28, 2026 06:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Set GIT_TERMINAL_PROMPT=0 for git ls-remote calls to prevent
  credential prompts from blocking dry-run in automation scenarios
- Add returncode assertion to test_dry_run_with_timestamp git
  branch --list check

Assisted-By: 🤖 Claude Code
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rhuss rhuss requested a review from mnriem March 28, 2026 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants