Skip to content

fix(powershell): resolve SPECIFY_INIT_DIR without .NET Core-only API - #3753

Open
Quratulain-bilal wants to merge 1 commit into
github:mainfrom
Quratulain-bilal:fix/ps51-triminitdir
Open

fix(powershell): resolve SPECIFY_INIT_DIR without .NET Core-only API#3753
Quratulain-bilal wants to merge 1 commit into
github:mainfrom
Quratulain-bilal:fix/ps51-triminitdir

Conversation

@Quratulain-bilal

Copy link
Copy Markdown
Contributor

Fixes #3749

Problem

scripts/powershell/common.ps1 resolves the SPECIFY_INIT_DIR root with [System.IO.Path]::TrimEndingDirectorySeparator(...), which only exists on .NET Core. On Windows PowerShell 5.1 (.NET Framework) the call throws:

Method invocation failed because [System.IO.Path] does not contain a method named 'TrimEndingDirectorySeparator'.

so project-root resolution fails before any Spec Kit command can run whenever SPECIFY_INIT_DIR is set. PowerShell 7+ users are unaffected (the API exists there), which is why it went unnoticed. The same file already documents this incompatibility ~150 lines later and correctly uses .TrimEnd('/','').

Fix

Use the .TrimEnd('/','') approach the file already endorses, guarding the single case where the two differ — a bare drive root (C:\), where TrimEnd would strip the separator and yield an invalid C: — by preserving the original path there.

Verification

Reproduced and verified on Windows PowerShell 5.1 (5.1.26100, Desktop edition):

  • Old line: THROWS: Method invocation failed ... TrimEndingDirectorySeparator
  • New line: resolves correctly, .specify/ detected.

The existing @requires_pwsh tests in tests/test_init_dir.py already exercise this path (trailing-slash, relative, precedence, compose). On PS 5.1 6 of them fail on the current code and all pass with this fix; they continue to pass on pwsh 7+. Edge cases confirmed: C: oo�ar\ -> C: oo�ar, C: oo/ -> C: oo, C:\ -> C:\ (preserved), no-op when already clean.

common.ps1 resolved the SPECIFY_INIT_DIR root with
[System.IO.Path]::TrimEndingDirectorySeparator, which only exists on .NET
Core. On Windows PowerShell 5.1 (.NET Framework) the call throws 'Method
invocation failed ... does not contain a method named
TrimEndingDirectorySeparator', so root resolution fails before any command
runs whenever SPECIFY_INIT_DIR is set. PowerShell 7+ users are unaffected,
which is why it went unnoticed.

The same file already documents this incompatibility ~150 lines later and
uses .TrimEnd('/','\') there. Apply the same approach here, guarding the one
case where the two differ — a bare drive root ('C:\'), where TrimEnd would
strip the separator and yield an invalid 'C:' — by preserving the original.

The existing @requires_pwsh tests in tests/test_init_dir.py already exercise
this path (trailing-slash, relative, precedence, compose); they now pass on
Windows PowerShell 5.1 as well as pwsh 7+.

Fixes github#3749

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

Updates PowerShell project-root resolution for Windows PowerShell 5.1 compatibility.

Changes:

  • Replaces the .NET Core-only path API with TrimEnd.
  • Preserves Windows drive-root separators.
Show a summary per file
File Description
scripts/powershell/common.ps1 Updates SPECIFY_INIT_DIR path normalization.

Review details

Tip

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

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

Comment on lines +63 to +66
$initRoot = $resolved.Path.TrimEnd('/', '\')
if ($initRoot -match '^[A-Za-z]:$') {
$initRoot = $resolved.Path
}

@mnriem mnriem left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please address Copilot feedback and fix test & lint errors

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.

common.ps1 uses .NET Core-only TrimEndingDirectorySeparator, breaking SPECIFY_INIT_DIR on Windows PowerShell 5.1

3 participants