Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions src/code/InstallHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ private List<PSResourceInfo> ProcessRepositories(
allPkgsInstalled.AddRange(installedPkgs);
}

if (!_cmdletPassedIn.MyInvocation.BoundParameters.ContainsKey("WhatIf") && _pkgNamesToInstall.Count > 0)
if ((!_cmdletPassedIn.MyInvocation.BoundParameters.ContainsKey("WhatIf") || (SwitchParameter)_cmdletPassedIn.MyInvocation.BoundParameters["WhatIf"] == false) && _pkgNamesToInstall.Count > 0)
{
string repositoryWording = repositoryNamesToSearch.Count > 1 ? "registered repositories" : "repository";
_cmdletPassedIn.WriteError(new ErrorRecord(
Expand Down Expand Up @@ -624,7 +624,7 @@ private List<PSResourceInfo> InstallPackages(
}

// If -WhatIf is passed in, early out.
if (_cmdletPassedIn.MyInvocation.BoundParameters.ContainsKey("WhatIf"))
if (_cmdletPassedIn.MyInvocation.BoundParameters.ContainsKey("WhatIf") && (SwitchParameter)_cmdletPassedIn.MyInvocation.BoundParameters["WhatIf"] == true)
{
return pkgsSuccessfullyInstalled;
}
Expand Down
23 changes: 13 additions & 10 deletions src/code/RegisterPSResourceRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,20 @@ protected override void ProcessRecord()
break;

case PSGalleryParameterSet:
try
{
items.Add(PSGalleryParameterSetHelper(Priority, Trusted));
}
catch (Exception e)
if (PSGallery)
{
ThrowTerminatingError(new ErrorRecord(
new PSInvalidOperationException(e.Message),
"ErrorInPSGalleryParameterSet",
ErrorCategory.InvalidArgument,
this));
try
{
items.Add(PSGalleryParameterSetHelper(Priority, Trusted));
}
catch (Exception e)
{
ThrowTerminatingError(new ErrorRecord(
new PSInvalidOperationException(e.Message),
"ErrorInPSGalleryParameterSet",
ErrorCategory.InvalidArgument,
this));
}
}
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,12 @@ Describe 'Test Install-PSResource for searching and looping through repositories
$err | Should -HaveCount 0
$warningVar | Should -Not -BeNullOrEmpty
}

It "install resources from repository should respect WhatIf value of false" {
# Package "test_module" exists in the following repositories (in this order): localRepo, PSGallery, NuGetGallery
$res = Install-PSResource -Name $testModuleName -Repository $PSGalleryName -TrustRepository -SkipDependencyCheck -PassThru -WhatIf:$false
$res | Should -Not -BeNullOrEmpty
$res.Name | Should -Be $testModuleName
$res.Repository | Should -Be $PSGalleryName
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ Describe "Test Register-PSResourceRepository" -tags 'CI' {
$res.Priority | Should -Be 50
}

It "register repository with PSGallery switch parameter value of false (PSGalleryParameterSet)" {
Unregister-PSResourceRepository -Name $PSGalleryName
$res = Register-PSResourceRepository -PSGallery:$false -PassThru
$res | Should -BeNullOrEmpty
}

It "register repository with PSGallery, Trusted parameters (PSGalleryParameterSet)" {
Unregister-PSResourceRepository -Name $PSGalleryName
$res = Register-PSResourceRepository -PSGallery -Trusted -PassThru
Expand Down