From ada68fea00c92c6839238cfdd44a3e4876e8c841 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 | 4 ++++ .../configuration/ChocolateyConfiguration.cs | 1 + .../services/NugetService.cs | 23 +++++++++++++------ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs index ec42a2cb74..b4c5a8415e 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs @@ -235,6 +235,10 @@ public virtual void ConfigureArgumentParser(OptionSet optionSet, ChocolateyConfi "Skip hooks - Do not run hook scripts. Available in 1.2.0+", option => configuration.SkipHookScripts = option != null ) + .Add("bypass-pins|ignore-pins", + "Bypass Pin(s) - Bypass any pins and upgrade the packages anyways. Defaults to false. Available in 2.2.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 69f38cbbb1..ddfe141fd3 100644 --- a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs +++ b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs @@ -583,6 +583,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 fe0d8e76c5..e7e201a691 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -1039,7 +1039,7 @@ public virtual ConcurrentDictionary Upgrade(ChocolateyCon var pkgInfo = _packageInfoService.Get(installedPackage.PackageMetadata); bool isPinned = pkgInfo != null && pkgInfo.IsPinned; - if (isPinned && config.OutdatedCommand.IgnorePinned) + if (isPinned && config.OutdatedCommand.IgnorePinned && !config.UpgradeCommand.BypassPins) { continue; } @@ -1168,12 +1168,21 @@ public virtual ConcurrentDictionary Upgrade(ChocolateyCon if (isPinned) { - string logMessage = "{0} is pinned. Skipping pinned package.".FormatWith(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; + if (!config.UpgradeCommand.BypassPins) + { + string logMessage = "{0} is pinned. Skipping pinned package.".FormatWith(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; + } + 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; + } } if (performAction)