Skip to content

Commit

Permalink
(#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 Jan 17, 2022
1 parent fe0b74f commit 77d8f45
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
"Pin Package - Add a pin to the package after upgrade. Available in 0.11.12+",
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 0.12.0+",
option => configuration.UpgradeCommand.BypassPins = option != null)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,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
25 changes: 19 additions & 6 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ public virtual ConcurrentDictionary<string, PackageResult> 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;
}
Expand Down Expand Up @@ -812,12 +812,25 @@ public virtual ConcurrentDictionary<string, PackageResult> 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);
Expand Down

0 comments on commit 77d8f45

Please sign in to comment.