From 457dc089904b51fc572f552f04f45287612dc11d Mon Sep 17 00:00:00 2001 From: TheCakeIsNaOH Date: Sat, 20 Nov 2021 18:49:41 -0600 Subject: [PATCH] (#2050) Upgrade add parameter to bypass pins This adds a switch to the upgrade command to bypass/ignore any pinned packages. It will write out a warning message if a pinned package is being upgraded. The package will remain pinned after the upgrade completes, although pinned to the new version. --- .../commands/ChocolateyUpgradeCommand.cs | 3 +++ .../configuration/ChocolateyConfiguration.cs | 1 + .../services/NugetService.cs | 25 ++++++++++++++----- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs index 14548d809f..03859aee40 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs @@ -222,6 +222,9 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon "Pin Package - Add a pin to the package after upgrade. Available in 1.2.0+", option => configuration.PinPackage = option != null ) + .Add("bypass-pins|ignore-pins", + "Bypass Pin(s) - Bypass any pins and upgrade the packages anyways. Defaults to false. Available in 1.0.0+", + option => configuration.UpgradeCommand.BypassPins = option != null) ; } diff --git a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs index ca4ee25576..2eeae4028a 100644 --- a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs +++ b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs @@ -458,6 +458,7 @@ public sealed class UpgradeCommandConfiguration public bool NotifyOnlyAvailableUpgrades { get; set; } public string PackageNamesToSkip { get; set; } public bool ExcludePrerelease { get; set; } + public bool BypassPins { get; set; } } [Serializable] diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index 26208cf271..071083108f 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -680,7 +680,7 @@ public virtual ConcurrentDictionary upgrade_run(Chocolate var pkgInfo = _packageInfoService.get_package_information(installedPackage); bool isPinned = pkgInfo != null && pkgInfo.IsPinned; - if (isPinned && config.OutdatedCommand.IgnorePinned) + if (isPinned && config.OutdatedCommand.IgnorePinned && !config.UpgradeCommand.BypassPins) { continue; } @@ -812,12 +812,25 @@ public virtual ConcurrentDictionary upgrade_run(Chocolate if (isPinned) { - string logMessage = "{0} is pinned. Skipping pinned package.".format_with(packageName); - packageResult.Messages.Add(new ResultMessage(ResultType.Warn, logMessage)); - packageResult.Messages.Add(new ResultMessage(ResultType.Inconclusive, logMessage)); - if (config.RegularOutput) this.Log().Warn(ChocolateyLoggers.Important, logMessage); + if (!config.UpgradeCommand.BypassPins) + { + string logMessage = "{0} is pinned. Skipping pinned package.".format_with(packageName); + packageResult.Messages.Add(new ResultMessage(ResultType.Warn, logMessage)); + packageResult.Messages.Add(new ResultMessage(ResultType.Inconclusive, logMessage)); + if (config.RegularOutput) this.Log().Warn(ChocolateyLoggers.Important, logMessage); - continue; + continue; + } + else + { + string logMessage = "{0} is pinned. Upgrading pinned package anyway as bypass-pins is specified".format_with(packageName); + packageResult.Messages.Add(new ResultMessage(ResultType.Warn, logMessage)); + if (config.RegularOutput) this.Log().Warn(ChocolateyLoggers.Important, logMessage); + config.PinPackage = true; + + //Reset the config in ChocolateyPackageService in so the package will be re-pinned after install + resetConfigAction(config); + } } set_package_config_for_upgrade(config, pkgInfo);