fix: fall back to feature dir basename for empty CURRENT_BRANCH (#3026)#3229
Open
Noor-ul-ain001 wants to merge 3 commits into
Open
fix: fall back to feature dir basename for empty CURRENT_BRANCH (#3026)#3229Noor-ul-ain001 wants to merge 3 commits into
Noor-ul-ain001 wants to merge 3 commits into
Conversation
…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>
Contributor
There was a problem hiding this comment.
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_DIRbasename whenget_current_branch()is empty inget_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_FEATUREremains 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 on lines
+193
to
+195
| if [[ -z "$current_branch" ]]; then | ||
| current_branch="${feature_dir##*/}" | ||
| fi |
Collaborator
|
Please address Copilot feedback |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
When a feature is resolved via
SPECIFY_FEATURE_DIRECTORYor.specify/feature.jsonwithoutSPECIFY_FEATUREset,get_current_branch()returns empty, soget_feature_paths/Get-FeaturePathsEnvemittedCURRENT_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:
scripts/bash/common.sh):current_branch="${feature_dir##*/}"scripts/powershell/common.ps1):$currentBranch = Split-Path -Leaf $featureDirAn explicit
SPECIFY_FEATUREstill 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_FEATUREunset and the feature pinned infeature.json:Tests
Added regression tests (bash + PowerShell) to
tests/test_check_prerequisites_paths_only.py:(test_|test_ps_)current_branch_falls_back_to_feature_dir_basename—BRANCHequals the feature dir basename whenSPECIFY_FEATUREis unset.test_explicit_feature_still_overrides_basename—SPECIFY_FEATUREremains authoritative.Verified the PowerShell test fails on
main(emptyBRANCH) and passes with the fix; existing paths-only tests still pass;ruffclean. (Bash tests run on CI; they skip on my local Windows pytest env wherebashisn't on the pytest PATH, but I reproduced the bash behavior directly as shown above.)🤖 Generated with Claude Code