From e4727bf997138271f96f20db92357fed4bf6202d 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 ignore 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 | 30 ++++++++++++++----- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs index c7b6e94b56..975f801999 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs @@ -250,6 +250,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("ignore-pin", + "Ignore Pin - Ignores any pins and upgrades the package(s) anyway. Available in 2.3.0+", + option => configuration.UpgradeCommand.IgnorePin = option != null + ) ; } diff --git a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs index 426fa92288..eaaacbccab 100644 --- a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs +++ b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs @@ -600,6 +600,7 @@ public sealed class UpgradeCommandConfiguration public bool NotifyOnlyAvailableUpgrades { get; set; } public string PackageNamesToSkip { get; set; } public bool ExcludePrerelease { get; set; } + public bool IgnorePin { get; set; } } [Serializable] diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index 3184a614f5..8b30775200 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -1108,7 +1108,7 @@ public virtual ConcurrentDictionary Upgrade(ChocolateyCon var pkgInfo = _packageInfoService.Get(installedPackage.PackageMetadata); var isPinned = pkgInfo != null && pkgInfo.IsPinned; - if (isPinned && config.OutdatedCommand.IgnorePinned) + if (isPinned && config.OutdatedCommand.IgnorePinned && !config.UpgradeCommand.IgnorePin) { continue; } @@ -1246,15 +1246,31 @@ public virtual ConcurrentDictionary Upgrade(ChocolateyCon if (isPinned) { - var 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) + if (!config.UpgradeCommand.IgnorePin) { - this.Log().Warn(ChocolateyLoggers.Important, logMessage); + var 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 + { + var logMessage = "{0} is pinned. Upgrading pinned package anyway as ignore pin is specified".FormatWith(packageName); + packageResult.Messages.Add(new ResultMessage(ResultType.Warn, logMessage)); - continue; + if (config.RegularOutput) + { + this.Log().Warn(ChocolateyLoggers.Important, logMessage); + } + + config.PinPackage = true; + } } if (performAction)