fix(Git): use full Dependency.Target path when target doesn't exist#169
Merged
HeyItsGilbert merged 4 commits intoMay 15, 2026
Merged
Conversation
Split-Path -Leaf + Join-Path $PWD broke absolute paths and multi-level targets, and crashed when Dependency.Target was empty. Now $Target is set to the full Dependency.Target value; existing New-Item at line 109 handles directory creation. Adds a Pester regression test for the full-path behavior. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
557ddbf to
97ca268
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a bug in Git.ps1 where the -Force branch incorrectly used Split-Path -Leaf + Join-Path $PWD to construct the target path, which clobbered absolute or multi-level target paths and threw when Dependency.Target was empty. The else-branch is now simplified to assign $Dependency.Target directly when present, relying on the existing New-Item at line 111 to create the directory.
Changes:
- Replaced the broken
-Force/Split-Pathbranch inGit.ps1with a direct$Target = $Dependency.Targetassignment, preserving the$PWDdefault when no target is set. - Added a Pester regression context asserting
New-Itemis invoked with the fullDependency.Targetpath rather than just the leaf joined to$PWD.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| PSDepend/PSDependScripts/Git.ps1 | Replaces the flawed -Force/Split-Path logic with a direct assignment of $Dependency.Target, falling back to $PWD.Path only when no target is provided. |
| Tests/PSModuleGallery.Type.Tests.ps1 | Adds a regression context verifying New-Item receives the full target path from git.depend.psd1 (TestDrive:/PSDependPesterTest\buildhelpers). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Using $Dependency.Target raw caused TestDrive: (and other PSDrive) paths to be passed directly to filesystem APIs inside the module, where the PSDrive may not resolve. Mirror how the existing-path branch normalizes via Get-Item.FullName, using GetUnresolvedProviderPathFromPSPath for paths that don't exist yet. Also scope the Test-Path mock in the regression test to only intercept the target path, preventing the mock from breaking Invoke-PSDepend's own -Path parameter validation. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.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.
Supersedes #99 — that PR has been open since 2019 with no merge activity, so filing a fresh one with the fixes applied.
Problem
The
-Forcebranch inGit.ps1usedSplit-Path -Leaf+Join-Path $PWDto construct the target path. This breaks in two ways:C:\Temp\Repos\myrepo,TestDrive:/PSDependPesterTest\buildhelpers) are clobbered — only the leaf is used and it lands in$PWDinstead of the intended location.-Forceis used without aDependency.Target,Split-Paththrows because the input is empty.Fix
In the unresolvable-target
elseblock, simply set$Target = $Dependency.Targetwhen it is non-empty. The existingNew-Itemcall at line 109 already handles directory creation for theInstallaction — no duplication needed. WhenDependency.Targetis empty the previous default-to-$PWDbehavior is preserved.Changes
PSDepend/PSDependScripts/Git.ps1— replaced the broken-Force/Split-Pathbranch with a clean$Dependency.TargetassignmentTests/PSModuleGallery.Type.Tests.ps1— added a Pester regression context that assertsNew-Itemis called with the full target path, not just the leaf joined to$PWD