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

(#3292) Ensure pre-release flag is used for parent lookup #3293

Merged
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
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