Skip to content

Commit

Permalink
Merge pull request #3293 from AdmiringWorm/bugfix/3292-Unable-to-upgr…
Browse files Browse the repository at this point in the history
…ade-package-if-p

(#3292) Ensure pre-release flag is used for parent lookup
  • Loading branch information
gep13 authored Aug 4, 2023
2 parents 680c1eb + 235c4b7 commit e442793
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1234,8 +1234,21 @@ public virtual ConcurrentDictionary<string, PackageResult> Upgrade(ChocolateyCon
}
}

var configPrerelease = config.Prerelease;
config.Prerelease = parentPackage.Version.IsPrerelease;

var availablePackageDependency = NugetList.FindPackage(parentPackage.Id, config, _nugetLogger, sourceCacheContext, remoteEndpoints);
NugetCommon.GetPackageDependencies(availablePackageDependency.Identity, NuGetFramework.AnyFramework, sourceCacheContext, _nugetLogger, remoteEndpoints, sourcePackageDependencyInfos, sourceDependencyCache, config).GetAwaiter().GetResult();

config.Prerelease = configPrerelease;

if (availablePackageDependency != null)
{
NugetCommon.GetPackageDependencies(availablePackageDependency.Identity, NuGetFramework.AnyFramework, sourceCacheContext, _nugetLogger, remoteEndpoints, sourcePackageDependencyInfos, sourceDependencyCache, config).GetAwaiter().GetResult();
}
else
{
this.Log().Warn("Unable to find the parent package '{0}'.", parentPackage.Id);
}
}

var removedSources = RemovePinnedSourceDependencies(sourcePackageDependencyInfos, allLocalPackages);
Expand Down Expand Up @@ -1297,7 +1310,6 @@ public virtual ConcurrentDictionary<string, PackageResult> Upgrade(ChocolateyCon
}
}
}

}
else
{
Expand Down
27 changes: 27 additions & 0 deletions tests/chocolatey-tests/commands/choco-upgrade.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,33 @@ To upgrade a local, or remote file, you may use:
}
}

Context 'Upgrading a package where parent only contain pre-releases' -Tag Testing {
BeforeAll {
Restore-ChocolateyInstallSnapshot

$null = Invoke-Choco install isdependency --version 1.0.0
$null = Invoke-Choco install hasstabledependency

$Output = Invoke-Choco upgrade isdependency --version 2.0.0
}

It "Should exit with sucess (0)" {
$Output.ExitCode | Should -Be 0 -Because $Output.String
}

It "Should report successful upgrade" {
$Output.Lines | Should -Contain "isdependency v2.0.0" -Because $Output.String
$Output.Lines | Should -Contain "Chocolatey upgraded 1/1 packages." -Because $Output.String
}

It "Should have upgraded the correct files" {
$ExpectedFile = "${env:ChocolateyInstall}/lib/isdependency/isdependency"
"$ExpectedFile.nupkg" | Should -Exist
$NuspecContent = [xml](Get-Content "$ExpectedFile.nuspec")
$NuspecContent.package.metadata.version | Should -Be "2.0.0"
}
}

# This needs to be (almost) the last test in this block, to ensure NuGet configurations aren't being created.
# Any tests after this block are expected to generate the configuration as they're explicitly using the NuGet CLI
Test-NuGetPaths
Expand Down

0 comments on commit e442793

Please sign in to comment.