From 6a4c515ab58b07856f1f2d33b1384ac3a740ab9c Mon Sep 17 00:00:00 2001 From: alerickson Date: Fri, 16 Oct 2026 10:44:36 -0700 Subject: [PATCH 1/2] Bug fix for set-psresourcerepository dynamic parameter --- src/code/SetPSResourceRepository.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/code/SetPSResourceRepository.cs b/src/code/SetPSResourceRepository.cs index 293db33e9..955bb207b 100644 --- a/src/code/SetPSResourceRepository.cs +++ b/src/code/SetPSResourceRepository.cs @@ -109,6 +109,7 @@ public SwitchParameter Trusted public object GetDynamicParameters() { + RepositorySettings.CheckRepositoryStore(); PSRepositoryInfo repository = RepositorySettings.Read(new[] { Name }, out string[] _).FirstOrDefault(); // Dynamic parameter '-CredentialProvider' should not appear for PSGallery, MAR, or any container registry repository. // It should also not appear when using the 'Repositories' parameter set. @@ -129,11 +130,6 @@ public object GetDynamicParameters() #region Private methods - protected override void BeginProcessing() - { - RepositorySettings.CheckRepositoryStore(); - } - protected override void ProcessRecord() { // determine if either 1 of 5 values are attempting to be set: Uri, Priority, Trusted, APIVersion, CredentialInfo. From 9790267c22fde59d0855455583930a165909e988 Mon Sep 17 00:00:00 2001 From: alerickson Date: Fri, 16 Oct 2026 17:20:31 -0700 Subject: [PATCH 2/2] Add regression test --- .../SetPSResourceRepository.Tests.ps1 | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/ResourceRepositoryTests/SetPSResourceRepository.Tests.ps1 b/test/ResourceRepositoryTests/SetPSResourceRepository.Tests.ps1 index 3a4d4f10c..eb244c5bd 100644 --- a/test/ResourceRepositoryTests/SetPSResourceRepository.Tests.ps1 +++ b/test/ResourceRepositoryTests/SetPSResourceRepository.Tests.ps1 @@ -41,6 +41,20 @@ Describe "Test Set-PSResourceRepository" -tags 'CI' { Get-RemoveTestDirs($tmpDirPaths) } + It "set PSGallery trust when repository store file doesn't exist" { + $powerShellGetPath = Join-Path -Path ([Environment]::GetFolderPath([System.Environment+SpecialFolder]::LocalApplicationData)) -ChildPath "PSResourceGet" + $repoFilePath = Join-Path -Path $powerShellGetPath -ChildPath "PSResourceRepository.xml" + Remove-Item -LiteralPath $repoFilePath -Force -ErrorAction Stop + Test-Path -LiteralPath $repoFilePath | Should -Be False + + $result = Set-PSResourceRepository -Name PSGallery -Trusted -PassThru -ErrorAction Stop + + Test-Path -LiteralPath $repoFilePath | Should -Be True + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be $PSGalleryName + $result.Trusted | Should -Be True + } + It "set repository given Name and Uri parameters" { Register-PSResourceRepository -Name $TestRepoName1 -Uri $tmpDir1Path Set-PSResourceRepository -Name $TestRepoName1 -Uri $tmpDir2Path