Skip to content

fix: fall back to feature dir basename for empty CURRENT_BRANCH (#3026)#3229

Open
Noor-ul-ain001 wants to merge 3 commits into
github:mainfrom
Noor-ul-ain001:fix/3026-current-branch-fallback
Open

fix: fall back to feature dir basename for empty CURRENT_BRANCH (#3026)#3229
Noor-ul-ain001 wants to merge 3 commits into
github:mainfrom
Noor-ul-ain001:fix/3026-current-branch-fallback

Conversation

@Noor-ul-ain001

Copy link
Copy Markdown
Contributor

What

When a feature is resolved via SPECIFY_FEATURE_DIRECTORY or .specify/feature.json without SPECIFY_FEATURE set, get_current_branch() returns empty, so get_feature_paths / Get-FeaturePathsEnv emitted CURRENT_BRANCH= (empty) / BRANCH: "" even though the feature directory was fully resolvable. Downstream scripts and agents that expect a non-empty identifier got misleading, silent empty output.

Fixes #3026.

How

Fall back to the basename of the resolved feature directory when the branch is empty, in both resolvers:

  • bash (scripts/bash/common.sh): current_branch="${feature_dir##*/}"
  • PowerShell (scripts/powershell/common.ps1): $currentBranch = Split-Path -Leaf $featureDir

An explicit SPECIFY_FEATURE still takes precedence (it's read before this fallback), so this only fills the previously-empty case — no change for users who set the feature explicitly.

Verification

Reproduced end-to-end (bash), with SPECIFY_FEATURE unset and the feature pinned in feature.json:

=== BEFORE FIX ===  BRANCH= ''
=== AFTER FIX  ===  BRANCH= '001-my-feature'
=== AFTER FIX (SPECIFY_FEATURE=my-branch override) ===  BRANCH= 'my-branch'

Tests

Added regression tests (bash + PowerShell) to tests/test_check_prerequisites_paths_only.py:

  • (test_|test_ps_)current_branch_falls_back_to_feature_dir_basenameBRANCH equals the feature dir basename when SPECIFY_FEATURE is unset.
  • test_explicit_feature_still_overrides_basenameSPECIFY_FEATURE remains authoritative.

Verified the PowerShell test fails on main (empty BRANCH) and passes with the fix; existing paths-only tests still pass; ruff clean. (Bash tests run on CI; they skip on my local Windows pytest env where bash isn't on the pytest PATH, but I reproduced the bash behavior directly as shown above.)

🤖 Generated with Claude Code

…ub#3026)

When a feature is resolved via SPECIFY_FEATURE_DIRECTORY or .specify/feature.json
without SPECIFY_FEATURE set, get_current_branch() returns empty, so
get_feature_paths / Get-FeaturePathsEnv emitted CURRENT_BRANCH= (empty) even
though the feature directory was resolvable. Downstream scripts and agents that
expect a non-empty identifier got misleading output.

Fall back to the basename of the resolved feature directory when the branch is
empty, in both the bash (`${feature_dir##*/}`) and PowerShell
(`Split-Path -Leaf`) resolvers. An explicit SPECIFY_FEATURE still takes
precedence, so this only fills the previously-empty case.

Add bash + PowerShell regression tests: the basename fallback fires when
SPECIFY_FEATURE is unset, and an explicit SPECIFY_FEATURE still overrides it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a paths-only resolution edge case where feature context is resolvable (via SPECIFY_FEATURE_DIRECTORY or .specify/feature.json) but SPECIFY_FEATURE is unset, causing CURRENT_BRANCH/BRANCH to be emitted as an empty string. It adds a fallback that uses the resolved feature directory’s basename as a usable identifier, and introduces regression tests covering the behavior.

Changes:

  • Bash: fall back to FEATURE_DIR basename when get_current_branch() is empty in get_feature_paths().
  • PowerShell: apply the same basename fallback in Get-FeaturePathsEnv.
  • Tests: add bash + PowerShell regression tests to assert the fallback behavior and that explicit SPECIFY_FEATURE remains authoritative.
Show a summary per file
File Description
scripts/bash/common.sh Adds CURRENT_BRANCH fallback to the resolved feature directory basename when explicit branch context is absent.
scripts/powershell/common.ps1 Adds the same fallback for CURRENT_BRANCH in the PowerShell resolver.
tests/test_check_prerequisites_paths_only.py Adds regression tests validating the basename fallback and explicit override behavior for both bash and PowerShell.

Review details

Tip

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

  • Files reviewed: 3/3 changed files
  • Comments generated: 2
  • Review effort level: Low

Comment thread scripts/bash/common.sh
Comment on lines +193 to +195
if [[ -z "$current_branch" ]]; then
current_branch="${feature_dir##*/}"
fi
Comment thread scripts/powershell/common.ps1
@mnriem

mnriem commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Please address Copilot feedback

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review details

  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Low

Comment thread scripts/bash/common.sh
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.

[Bug]: get_feature_paths emits empty CURRENT_BRANCH when SPECIFY_FEATURE unset, despite feature context via SPECIFY_FEATURE_DIRECTORY/feature.json

3 participants