Skip to content

fix(Git): use full Dependency.Target path when target doesn't exist#169

Merged
HeyItsGilbert merged 4 commits into
PowerShellOrg:masterfrom
HeyItsGilbert:rcarboneras/master
May 15, 2026
Merged

fix(Git): use full Dependency.Target path when target doesn't exist#169
HeyItsGilbert merged 4 commits into
PowerShellOrg:masterfrom
HeyItsGilbert:rcarboneras/master

Conversation

@HeyItsGilbert
Copy link
Copy Markdown
Member

Supersedes #99 — that PR has been open since 2019 with no merge activity, so filing a fresh one with the fixes applied.

Problem

The -Force branch in Git.ps1 used Split-Path -Leaf + Join-Path $PWD to construct the target path. This breaks in two ways:

  1. Absolute paths or multi-level targets (e.g. C:\Temp\Repos\myrepo, TestDrive:/PSDependPesterTest\buildhelpers) are clobbered — only the leaf is used and it lands in $PWD instead of the intended location.
  2. When -Force is used without a Dependency.Target, Split-Path throws because the input is empty.

Fix

In the unresolvable-target else block, simply set $Target = $Dependency.Target when it is non-empty. The existing New-Item call at line 109 already handles directory creation for the Install action — no duplication needed. When Dependency.Target is empty the previous default-to-$PWD behavior is preserved.

Changes

  • PSDepend/PSDependScripts/Git.ps1 — replaced the broken -Force/Split-Path branch with a clean $Dependency.Target assignment
  • Tests/PSModuleGallery.Type.Tests.ps1 — added a Pester regression context that asserts New-Item is called with the full target path, not just the leaf joined to $PWD

Copilot AI review requested due to automatic review settings May 15, 2026 21:16
rcarboneras and others added 3 commits May 15, 2026 14:16
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>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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-Path branch in Git.ps1 with a direct $Target = $Dependency.Target assignment, preserving the $PWD default when no target is set.
  • Added a Pester regression context asserting New-Item is invoked with the full Dependency.Target path 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>
@HeyItsGilbert HeyItsGilbert merged commit b077f24 into PowerShellOrg:master May 15, 2026
4 checks passed
@HeyItsGilbert HeyItsGilbert deleted the rcarboneras/master branch May 15, 2026 21:28
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.

3 participants