From 3381510a7ba8dadba32d0e1f0d6797be7638a417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Carboneras?= Date: Wed, 8 May 2019 21:31:28 +0200 Subject: [PATCH 1/4] Update Git.ps1 --- PSDepend/PSDependScripts/Git.ps1 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/PSDepend/PSDependScripts/Git.ps1 b/PSDepend/PSDependScripts/Git.ps1 index 0483898..c63d057 100644 --- a/PSDepend/PSDependScripts/Git.ps1 +++ b/PSDepend/PSDependScripts/Git.ps1 @@ -93,8 +93,14 @@ if($Dependency.Target -and ($Target = (Get-Item $Dependency.Target -ErrorAction } else { - $Target = $PWD.Path - Write-Debug "Target defaulted to current dir: $Target" +if ($Force) {New-Item -ItemType Directory -Name $Dependency.Target -Force | Out-Null + Write-Debug "Target folder $($Dependency.Target) created as -Force switch was specified" + $Target = Join-Path $PWD "$($Dependency.Target)" + } + else { + $Target = $PWD.Path + Write-Debug "Target defaulted to current dir: $Target" + } } $RepoPath = Join-Path $Target $GitName $GottaInstall = $True From b3179839c1388b75ce916ccaf15b3827c599f2f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Carboneras?= Date: Thu, 9 May 2019 09:54:02 +0200 Subject: [PATCH 2/4] Update Git.ps1 --- PSDepend/PSDependScripts/Git.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/PSDepend/PSDependScripts/Git.ps1 b/PSDepend/PSDependScripts/Git.ps1 index c63d057..a4a79fb 100644 --- a/PSDepend/PSDependScripts/Git.ps1 +++ b/PSDepend/PSDependScripts/Git.ps1 @@ -93,9 +93,10 @@ if($Dependency.Target -and ($Target = (Get-Item $Dependency.Target -ErrorAction } else { -if ($Force) {New-Item -ItemType Directory -Name $Dependency.Target -Force | Out-Null +if ($Force) { + New-Item -ItemType Directory -Name (Split-Path $Dependency.Target -Leaf) -Force | Out-Null Write-Debug "Target folder $($Dependency.Target) created as -Force switch was specified" - $Target = Join-Path $PWD "$($Dependency.Target)" + $Target = Join-Path $PWD "$(Split-Path $Dependency.Target -Leaf)" } else { $Target = $PWD.Path From 97ca268ab1be2284ef949222bc598680baaae49a Mon Sep 17 00:00:00 2001 From: Gilbert Sanchez Date: Fri, 15 May 2026 14:13:24 -0700 Subject: [PATCH 3/4] fix(Git): use full Dependency.Target path when target doesn't exist 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 --- PSDepend/PSDependScripts/Git.ps1 | 11 +++++------ Tests/PSModuleGallery.Type.Tests.ps1 | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/PSDepend/PSDependScripts/Git.ps1 b/PSDepend/PSDependScripts/Git.ps1 index a4a79fb..b5b5076 100644 --- a/PSDepend/PSDependScripts/Git.ps1 +++ b/PSDepend/PSDependScripts/Git.ps1 @@ -93,15 +93,14 @@ if($Dependency.Target -and ($Target = (Get-Item $Dependency.Target -ErrorAction } else { -if ($Force) { - New-Item -ItemType Directory -Name (Split-Path $Dependency.Target -Leaf) -Force | Out-Null - Write-Debug "Target folder $($Dependency.Target) created as -Force switch was specified" - $Target = Join-Path $PWD "$(Split-Path $Dependency.Target -Leaf)" - } + if ($Dependency.Target) { + $Target = $Dependency.Target + Write-Debug "Target $($Dependency.Target) does not exist yet, will be created" + } else { $Target = $PWD.Path Write-Debug "Target defaulted to current dir: $Target" - } + } } $RepoPath = Join-Path $Target $GitName $GottaInstall = $True diff --git a/Tests/PSModuleGallery.Type.Tests.ps1 b/Tests/PSModuleGallery.Type.Tests.ps1 index dd2b8c3..68fb55f 100644 --- a/Tests/PSModuleGallery.Type.Tests.ps1 +++ b/Tests/PSModuleGallery.Type.Tests.ps1 @@ -512,6 +512,24 @@ Describe "PSModuleGallery Type" -Tag 'Integration' { } } + Context 'Creates non-existent Target directory using full path' { + BeforeAll { + Mock Invoke-ExternalCommand {} -ModuleName PSDepend -ParameterFilter { $Arguments -contains 'checkout' -or $Arguments -contains 'clone' } + Mock Push-Location {} -ModuleName PSDepend + Mock Pop-Location {} -ModuleName PSDepend + Mock Set-Location {} -ModuleName PSDepend + Mock Test-Path { return $False } -ModuleName PSDepend + Mock New-Item { [pscustomobject]@{ FullName = $Path } } -ModuleName PSDepend + $null = Invoke-PSDepend @Verbose -Path "$TestDepends\git.depend.psd1" -Force + } + + It 'Calls New-Item with the full Dependency.Target path, not just the leaf joined to $PWD' { + Should -Invoke New-Item -Times 1 -Exactly -Scope Context -ModuleName PSDepend -ParameterFilter { + $Path -eq 'TestDrive:/PSDependPesterTest\buildhelpers' + } + } + } + Context 'Tests dependency' { BeforeAll { Mock New-Item { return $true } -ModuleName PSDepend From 5593c4abcd4f8c8c7c86f04339e189051dcae800 Mon Sep 17 00:00:00 2001 From: Gilbert Sanchez Date: Fri, 15 May 2026 14:24:10 -0700 Subject: [PATCH 4/4] fix(Git): resolve target path via provider to handle PSDrives 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 --- PSDepend/PSDependScripts/Git.ps1 | 2 +- Tests/PSModuleGallery.Type.Tests.ps1 | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/PSDepend/PSDependScripts/Git.ps1 b/PSDepend/PSDependScripts/Git.ps1 index b5b5076..569fc51 100644 --- a/PSDepend/PSDependScripts/Git.ps1 +++ b/PSDepend/PSDependScripts/Git.ps1 @@ -94,7 +94,7 @@ if($Dependency.Target -and ($Target = (Get-Item $Dependency.Target -ErrorAction else { if ($Dependency.Target) { - $Target = $Dependency.Target + $Target = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Dependency.Target) Write-Debug "Target $($Dependency.Target) does not exist yet, will be created" } else { diff --git a/Tests/PSModuleGallery.Type.Tests.ps1 b/Tests/PSModuleGallery.Type.Tests.ps1 index 68fb55f..feabd7c 100644 --- a/Tests/PSModuleGallery.Type.Tests.ps1 +++ b/Tests/PSModuleGallery.Type.Tests.ps1 @@ -518,14 +518,14 @@ Describe "PSModuleGallery Type" -Tag 'Integration' { Mock Push-Location {} -ModuleName PSDepend Mock Pop-Location {} -ModuleName PSDepend Mock Set-Location {} -ModuleName PSDepend - Mock Test-Path { return $False } -ModuleName PSDepend + Mock Test-Path { return $False } -ModuleName PSDepend -ParameterFilter { $Path -match 'buildhelpers' } Mock New-Item { [pscustomobject]@{ FullName = $Path } } -ModuleName PSDepend $null = Invoke-PSDepend @Verbose -Path "$TestDepends\git.depend.psd1" -Force } - It 'Calls New-Item with the full Dependency.Target path, not just the leaf joined to $PWD' { + It 'Calls New-Item with a path containing the full target name, not just the leaf joined to $PWD' { Should -Invoke New-Item -Times 1 -Exactly -Scope Context -ModuleName PSDepend -ParameterFilter { - $Path -eq 'TestDrive:/PSDependPesterTest\buildhelpers' + $Path -match 'buildhelpers' -and $Path -notmatch [regex]::Escape($PWD.Path) } } }