Skip to content

Commit

Permalink
(chocolatey#2050) Upgrade add parameter to bypass pins
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TheCakeIsNaOH committed Dec 14, 2023
1 parent ff37b55 commit da39599
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 BypassPins { get; set; }
}

[Serializable]
Expand Down
23 changes: 16 additions & 7 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ public virtual ConcurrentDictionary<string, PackageResult> 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;
}
Expand Down Expand Up @@ -1174,12 +1174,21 @@ public virtual ConcurrentDictionary<string, PackageResult> 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)
Expand Down

0 comments on commit da39599

Please sign in to comment.