Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(GH-994) Add ignore-pinned switch to outdated command. #1123

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ $commandOptions = @{
info = "--pre --lo --source='' --user= --password= --local-only --prerelease" + $allcommands
install = "-y -whatif -? --pre --version= --params='' --install-arguments='' --override-arguments --ignore-dependencies --source='' --source='windowsfeatures' --source='webpi' --user= --password= --prerelease --forcex86 --not-silent --package-parameters='' --allow-downgrade --force-dependencies --require-checksums --use-package-exit-codes --ignore-package-exit-codes --skip-automation-scripts --allow-multiple-versions --ignore-checksums --allow-empty-checksums --allow-empty-checksums-secure --download-checksum='' --download-checksum-type='' --download-checksum-x64='' --download-checksum-type-x64=''" + $allcommands + $proInstallUpgradeOptions
pin = "--name= --version= -?" + $allcommands
outdated = "-? --source='' --user= --password=" + $allcommands
outdated = "-? --source='' --user= --password= --ignore-pinned" + $allcommands
upgrade = "-y -whatif -? --pre --version= --except='' --params='' --install-arguments='' --override-arguments --ignore-dependencies --source='' --source='windowsfeatures' --source='webpi' --user= --password= --prerelease --forcex86 --not-silent --package-parameters='' --allow-downgrade --allow-multiple-versions --require-checksums --use-package-exit-codes --ignore-package-exit-codes --skip-automation-scripts --fail-on-unfound --fail-on-not-installed --ignore-checksums --allow-empty-checksums --allow-empty-checksums-secure --download-checksum='' --download-checksum-type='' --download-checksum-x64='' --download-checksum-type-x64=''" + $allcommands + $proInstallUpgradeOptions
uninstall = "-y -whatif -? --force-dependencies --remove-dependencies --all-versions --source='windowsfeatures' --source='webpi' --version= --uninstall-arguments='' --override-arguments --not-silent --params='' --package-parameters='' --use-package-exit-codes --ignore-package-exit-codes --skip-automation-scripts --use-autouninstaller --skip-autouninstaller --fail-on-autouninstaller --ignore-autouninstaller-failure" + $allcommands
new = "--template-name= --file='Biz editions only' --automaticpackage --version= --maintainer='' packageversion= maintainername='' maintainerrepo='' installertype= url='' url64='' silentargs='' --use-built-in-template -?" + $allcommands
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ public void should_add_short_version_of_password_to_the_option_set()
{
optionSet.Contains("p").ShouldBeTrue();
}


[Fact]
public void should_add_ignore_pinned_to_the_option_set()
{
optionSet.Contains("ignore-pinned").ShouldBeTrue();
}
}

public class when_noop_is_called : ChocolateyOutdatedCommandSpecsBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
option => configuration.SourceCommand.Certificate = option.remove_surrounding_quotes())
.Add("cp=|certpassword=",
"Certificate Password - the client certificate's password to the source. Defaults to empty. Available in 0.9.10+.",
option => configuration.SourceCommand.CertificatePassword = option.remove_surrounding_quotes())
option => configuration.SourceCommand.CertificatePassword = option.remove_surrounding_quotes())
.Add("ignore-pinned",
"IgnorePinned - Ignore pinned packages. Defaults to false.",
option => configuration.OutdatedCommand.IgnorePinned = option != null)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace chocolatey.infrastructure.app.configuration
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using commands;
using domain;
using logging;
using platforms;
Expand Down Expand Up @@ -46,7 +47,8 @@ public ChocolateyConfiguration()
ApiKeyCommand = new ApiKeyCommandConfiguration();
PushCommand = new PushCommandConfiguration();
PinCommand = new PinCommandConfiguration();
Proxy = new ProxyConfiguration();
OutdatedCommand = new OutdatedCommandConfiguration();
Proxy = new ProxyConfiguration();
#if DEBUG
AllowUnofficialBuild = true;
#endif
Expand Down Expand Up @@ -111,7 +113,7 @@ private void output_tostring(StringBuilder propertyValues, IEnumerable<PropertyI
}

private const int MAX_CONSOLE_LINE_LENGTH = 72;
private int _currentLineLength = 0;
private int _currentLineLength = 0;

private void append_output(StringBuilder propertyValues, string append)
{
Expand Down Expand Up @@ -309,8 +311,16 @@ private void append_output(StringBuilder propertyValues, string append)
/// <remarks>
/// On .NET 4.0, get error CS0200 when private set - see http://stackoverflow.com/a/23809226/18475
/// </remarks>
public PinCommandConfiguration PinCommand { get; set; }

public PinCommandConfiguration PinCommand { get; set; }

/// <summary>
/// Configuration related specifically to Outdated command
/// </summary>
/// <remarks>
/// On .NET 4.0, get error CS0200 when private set - see http://stackoverflow.com/a/23809226/18475
/// </remarks>
public OutdatedCommandConfiguration OutdatedCommand { get; set; }

/// <summary>
/// Configuration related specifically to proxies.
/// </summary>
Expand Down Expand Up @@ -452,6 +462,12 @@ public sealed class PinCommandConfiguration
public PinCommandType Command { get; set; }
}

[Serializable]
public sealed class OutdatedCommandConfiguration
{
public bool IgnorePinned { get; set; }
}

[Serializable]
public sealed class ApiKeyCommandConfiguration
{
Expand Down
14 changes: 9 additions & 5 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -578,18 +578,22 @@ public ConcurrentDictionary<string, PackageResult> upgrade_run(ChocolateyConfigu
continue;
}

var pkgInfo = _packageInfoService.get_package_information(installedPackage);
bool isPinned = pkgInfo != null && pkgInfo.IsPinned;

if (isPinned && config.OutdatedCommand.IgnorePinned)
{
continue;
}

if (version != null && version < installedPackage.Version && !config.AllowMultipleVersions && !config.AllowDowngrade)
{
string logMessage = "A newer version of {0} (v{1}) is already installed.{2} Use --allow-downgrade or --force to attempt to upgrade to older versions, or use side by side to allow multiple versions.".format_with(installedPackage.Id, installedPackage.Version, Environment.NewLine);
var nullResult = packageInstalls.GetOrAdd(packageName, new PackageResult(installedPackage, _fileSystem.combine_paths(ApplicationParameters.PackagesLocation, installedPackage.Id)));
nullResult.Messages.Add(new ResultMessage(ResultType.Error, logMessage));
this.Log().Error(ChocolateyLoggers.Important, logMessage);
continue;
}

var pkgInfo = _packageInfoService.get_package_information(installedPackage);
bool isPinned = pkgInfo != null && pkgInfo.IsPinned;

}

IPackage availablePackage = packageManager.SourceRepository.FindPackage(packageName, version, config.Prerelease, allowUnlisted: false);
if (availablePackage == null)
Expand Down