fix: fall back to feature dir basename for empty CURRENT_BRANCH (#3026)#3229
fix: fall back to feature dir basename for empty CURRENT_BRANCH (#3026)#3229Noor-ul-ain001 wants to merge 6 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>
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
|
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>
|
Please address Copilot feedback. If not applicable, please explain why |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@mnriem i have commit copilot suggestions. |
|
Please address Copilot feedback. If not applicable, please explain why |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
mnriem
left a comment
There was a problem hiding this comment.
Please address Copilot feedback
|
@mnriem i have resolved conversation with copilot |
|
Did you address the feedback and commit it? I am not seeing it? |
- common.ps1: replace [System.IO.Path]::TrimEndingDirectorySeparator (a .NET Core-only method that throws MethodNotFound on Windows PowerShell 5.1 / .NET Framework) with a portable String.TrimEnd, so the trailing-slash trim actually works on 5.1. - tests: parametrize the bash fallback test to cover feature.json, SPECIFY_FEATURE_DIRECTORY, and the explicit SPECIFY_FEATURE override (mirrors the PowerShell test), folding in the old explicit-override test; add the missing blank line before the next test (PEP 8). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
@mnriem Apologies for the confusion — earlier I only resolved the review threads in the UI without pushing a follow-up commit, so there was nothing new for you to see. That's now fixed in commit d3b0f69, which addresses the remaining Copilot feedback:
Local run: |
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