Skip to content

Commit

Permalink
(GH-686) Upgrade Prereleases
Browse files Browse the repository at this point in the history
When a prerelease is installed, it should automatically be upgraded to
the newest absolute version (prerelease or stable) unless
`--exclude-prerelease` is specified. This means when running `choco
upgrade all`, all packages will be upgraded automatically in a way that
makes sense.
  • Loading branch information
ferventcoder committed Mar 19, 2017
1 parent 279988d commit 3ce7e90
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
"Stop On First Package Failure - stop running install, upgrade or uninstall on first package failure instead of continuing with others. Overrides the default feature '{0}' set to '{1}'. Available in 0.10.4+.".format_with(ApplicationParameters.Features.StopOnFirstPackageFailure, configuration.Features.StopOnFirstPackageFailure.to_string()),
option => configuration.Features.StopOnFirstPackageFailure = option != null
)
.Add("exclude-pre|exclude-prerelease|exclude-prereleases",
"Exclude Prerelease - Should prerelease be ignored for upgrades? Will be ignored if you pass `--pre`. Available in 0.10.4+.",
option => configuration.UpgradeCommand.ExcludePrerelease = option != null
)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ public sealed class UpgradeCommandConfiguration
public bool FailOnNotInstalled { get; set; }
public bool NotifyOnlyAvailableUpgrades { get; set; }
public string PackageNamesToSkip { get; set; }
public bool ExcludePrerelease { get; set; }
}

[Serializable]
Expand Down
9 changes: 9 additions & 0 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,17 @@ public ConcurrentDictionary<string, PackageResult> upgrade_run(ChocolateyConfigu
var pkgInfo = _packageInfoService.get_package_information(installedPackage);
bool isPinned = pkgInfo != null && pkgInfo.IsPinned;

// if we have a prerelease installed, we want to have it upgrade based on newer prereleases
var originalPrerelease = config.Prerelease;
if (!string.IsNullOrWhiteSpace(installedPackage.Version.SpecialVersion) && !config.UpgradeCommand.ExcludePrerelease)
{
// this is a prerelease - opt in for newer prereleases.
config.Prerelease = true;
}

IPackage availablePackage = packageManager.SourceRepository.FindPackage(packageName, version, config.Prerelease, allowUnlisted: false);
config.Prerelease = originalPrerelease;

if (availablePackage == null)
{
string logMessage = "{0} was not found with the source(s) listed.{1} If you specified a particular version and are receiving this message, it is possible that the package name exists but the version does not.{1} Version: \"{2}\"; Source(s): \"{3}\"".format_with(packageName, Environment.NewLine, config.Version, config.Sources);
Expand Down

0 comments on commit 3ce7e90

Please sign in to comment.