Skip to content

Commit be83442

Browse files
HeyItsGilbertclaude
andcommitted
fix: address PR review feedback
Chocolatey.ps1: - Fix synopsis grammar and replace stale Chocolatey.org references with the Chocolatey community repository - Document the Dependency and ChocoInstallScriptUrl parameters - Compare "have latest" versions SemanticVersion-first so prerelease versions (e.g. 2.2.2-beta) do not fall through to a reinstall FileSystem.ps1: - Report the specific missing $Source in the error, not the whole $Sources collection - Wire the documented Force switch: drop robocopy /XO so the target is overwritten even where its copy is newer Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 6e55c5d commit be83442

2 files changed

Lines changed: 33 additions & 9 deletions

File tree

PSDepend/PSDependScripts/Chocolatey.ps1

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
<#
22
.SYNOPSIS
3-
Installs a Chocolatey package a repository.
3+
Installs a package from a Chocolatey repository.
44
55
.DESCRIPTION
6-
Installs a package from a Chocolatey repository like Chocolatey.org.
6+
Installs a package from a Chocolatey repository like the Chocolatey community repository.
77
88
Relevant Dependency metadata:
99
Name: The name of the package
1010
Version: Used to identify existing installs meeting this criteria. Defaults to 'latest'
1111
Source: Source Uri. Defaults to https://community.chocolatey.org/api/v2/
1212
13+
.PARAMETER Dependency
14+
Dependency to process
15+
1316
.PARAMETER Force
1417
If specified and the package is already installed, force the install again.
1518
19+
.PARAMETER ChocoInstallScriptUrl
20+
Url to the script used to bootstrap Chocolatey when choco.exe is not found.
21+
Defaults to https://community.chocolatey.org/install.ps1
22+
1623
.PARAMETER PSDependAction
1724
Test, or Install the package. Defaults to Install
1825
@@ -27,7 +34,7 @@
2734
}
2835
}
2936
30-
# Install version 2.0.2 of git via Chocolatey.org
37+
# Install version 2.0.2 of git from the Chocolatey community repository
3138
3239
.EXAMPLE
3340
@{
@@ -54,7 +61,7 @@
5461
'putty' = 'latest'
5562
}
5663
57-
# Installs the list of Chocolatey packages from Chocolatey.org using the Global PSDependOptions to limit repetition.
64+
# Installs the list of Chocolatey packages from the Chocolatey community repository using the Global PSDependOptions to limit repetition.
5865
5966
#>
6067
[CmdletBinding()]
@@ -304,9 +311,23 @@ else {
304311
# If the version in the remote repository is less than or equal to the version installed, then we have the latest already
305312
[System.Version]$parsedRepositoryVersion = $null
306313
[System.Version]$parsedExistingVersion = $null
307-
$haveLatest = [System.Version]::TryParse($repositoryVersion, [ref]$parsedRepositoryVersion) -and
308-
[System.Version]::TryParse($existingVersion, [ref]$parsedExistingVersion) -and
314+
[System.Management.Automation.SemanticVersion]$parsedRepositorySemanticVersion = $null
315+
[System.Management.Automation.SemanticVersion]$parsedExistingSemanticVersion = $null
316+
$haveLatest = if (
317+
[System.Management.Automation.SemanticVersion]::TryParse([string]$repositoryVersion, [ref]$parsedRepositorySemanticVersion) -and
318+
[System.Management.Automation.SemanticVersion]::TryParse([string]$existingVersion, [ref]$parsedExistingSemanticVersion)
319+
) {
320+
$parsedRepositorySemanticVersion -le $parsedExistingSemanticVersion
321+
}
322+
elseif (
323+
[System.Version]::TryParse([string]$repositoryVersion, [ref]$parsedRepositoryVersion) -and
324+
[System.Version]::TryParse([string]$existingVersion, [ref]$parsedExistingVersion)
325+
) {
309326
$parsedRepositoryVersion -le $parsedExistingVersion
327+
}
328+
else {
329+
$false
330+
}
310331
if ($Version -eq 'latest' -and $haveLatest) {
311332
Write-Verbose "You have the latest version of [$Name], with installed version [$existingVersion] and Source version [$repositoryVersion]"
312333
if ($PSDependAction -contains 'Test') {

PSDepend/PSDependScripts/FileSystem.ps1

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ $TestOutput = @()
8585
foreach ($Source in @($Sources)) {
8686
if (-not (Test-Path $Source)) {
8787
if ($PSDependAction -notcontains 'Test') {
88-
Write-Error "Skipping $DependencyName, could not find source [$Sources]"
88+
Write-Error "Skipping $DependencyName, could not find source [$Source]"
8989
}
9090
continue
9191
}
@@ -108,8 +108,11 @@ foreach ($Source in @($Sources)) {
108108
}
109109
if ($PSDependAction -contains 'Install') {
110110
# TODO: Add non Windows equivalent...
111-
[string[]]$Arguments = "/XO"
112-
$Arguments += "/E"
111+
[string[]]$Arguments = "/E"
112+
if (-not ($Dependency.Parameters.Force -eq $True -or $Force)) {
113+
# Without -Force, skip files where the target copy is newer
114+
$Arguments += "/XO"
115+
}
113116
if ($Dependency.Parameters.Mirror -eq $True -or $Mirror) {
114117
$Arguments += "/PURGE"
115118
}

0 commit comments

Comments
 (0)