fix: derive paths-only branch from feature directory#3060
Conversation
There was a problem hiding this comment.
⚠️ Not ready to approve
The Bash fallback uses basename which won’t correctly derive a leaf name if feature_directory contains Windows-style backslashes, potentially producing an incorrect BRANCH value.
Pull request overview
This PR fixes check-prerequisites --paths-only / -PathsOnly emitting an empty BRANCH when SPECIFY_FEATURE is unset by deriving a fallback identifier from the resolved feature directory’s basename (supporting feature context coming from .specify/feature.json / SPECIFY_FEATURE_DIRECTORY).
Changes:
- Bash: derive
CURRENT_BRANCHfromFEATURE_DIRbasename whenSPECIFY_FEATUREis not set. - PowerShell: derive
CURRENT_BRANCHfromFEATURE_DIRleaf name whenSPECIFY_FEATUREis not set (trimming trailing separators first). - Add regression tests asserting
BRANCHis non-empty (and equals the feature directory basename) for both Bash and PowerShell paths-only JSON output.
File summaries
| File | Description |
|---|---|
scripts/bash/common.sh |
Adds fallback branch derivation from the resolved feature directory basename when explicit feature/branch state is absent. |
scripts/powershell/common.ps1 |
Adds fallback branch derivation from the resolved feature directory leaf when explicit feature/branch state is absent. |
tests/test_check_prerequisites_paths_only.py |
Adds regression tests for non-empty BRANCH fallback behavior in paths-only mode for Bash and PowerShell. |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 1
Note
Your feedback helps us improve the quality of this feature.
Please use 👍 or 👎 to tell us whether this assessment is correct.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if [[ -z "$current_branch" ]]; then | ||
| current_branch="$(basename "$feature_dir")" | ||
| fi |
mnriem
left a comment
There was a problem hiding this comment.
Please address Copilot feedback. If not applicable, please explain why
Description
Closes #3026 by deriving the paths-only
BRANCHvalue from the resolved feature directory basename when no explicitSPECIFY_FEATUREis available.This keeps
check-prerequisites --paths-only/-PathsOnlyuseful for feature-context invocations that rely on.specify/feature.jsoninstead of an active feature branch environment variable.Split out from #3053 after maintainer feedback to keep each bug fix in its own PR.
Testing
uv run specify --helpuv sync && uv run pytestAdditional validation run locally:
uv run --extra test pytest tests/test_check_prerequisites_paths_only.py -q- 4 passed, 5 skippeduvx ruff check tests/test_check_prerequisites_paths_only.py- passedgit diff --check- passedManual test results
Agent: Codex (GPT-5) | OS/Shell: Windows 11 / PowerShell 7.5.4
.specify/scripts/powershell/check-prerequisites.ps1 -Json -PathsOnlyBRANCHfallback from feature directory basename.AI Disclosure
This PR was implemented by Codex (GPT-5) acting as an AI coding agent on behalf of @luohui1. The agent read the repository contribution/security/code-of-conduct docs and issue templates, inspected the relevant code paths, implemented the changes, ran the validation listed above, and prepared this PR description.