Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix for Import-PSGetRepository in Windows PS #1460

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Microsoft.PowerShell.PSResourceGet.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function Import-PSGetRepository {

Microsoft.PowerShell.Utility\Write-Verbose ('Selected {0} NuGet repositories.' -f $repos.Count)
Copy link
Contributor

@kborowinski kborowinski Oct 25, 2023

Choose a reason for hiding this comment

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

@alerickson: The issue is also here, as $repos.Count will return $null on PowerShell 5.1, when only one repository was found, and therefore the verbose message will be misleading - "VERBOSE: Selected NuGet repositories" .

I suggest changing it either to @($repos).Count, or maybe, to make the code cleaner, we should assign the repos count to a variable, like this;

...
$reposCount = @(repos).Count
Microsoft.PowerShell.Utility\Write-Verbose ('Selected {0} NuGet repositories.' -f $reposCount)

if ($reposCount) {
...

or just convert the filtering result to an array:

...
$repos = @(
    $PSGetRepositories.Values |
        Microsoft.PowerShell.Core\Where-Object {$_.PackageManagementProvider -eq 'NuGet'-and $_.Name -ne 'PSGallery'} |
        Microsoft.PowerShell.Utility\Select-Object Name, Trusted, SourceLocation
)

Microsoft.PowerShell.Utility\Write-Verbose ('Selected {0} NuGet repositories.' -f $repos.Count)

if ($repos.Count) {
...

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for catching that, let me fix that


if ($repos.Count) {
if ($repos -ne $null) {
$repos | Microsoft.PowerShell.Core\ForEach-Object {
try {
$message = 'Registering {0} at {1} -Trusted:${2} -Force:${3}.' -f $_.Name,
Expand Down
Loading