Skip to content

Commit 974a3bc

Browse files
authored
Merge pull request chocolatey#2463 from TheCakeIsNaOH/install-pin
(chocolatey#798) Add parameter to install and upgrade commands to pin after install
2 parents c7d2276 + 48926cd commit 974a3bc

File tree

7 files changed

+67
-17
lines changed

7 files changed

+67
-17
lines changed

src/chocolatey.tests/infrastructure.app/commands/ChocolateyInstallCommandSpecs.cs

+18
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,24 @@ public void should_add_short_version_of_password_to_the_option_set()
235235
{
236236
optionSet.Contains("p").ShouldBeTrue();
237237
}
238+
239+
[Fact]
240+
public void should_add_pin_to_the_option_set()
241+
{
242+
optionSet.Contains("pinpackage").ShouldBeTrue();
243+
}
244+
245+
[Fact]
246+
public void should_add_long_version_of_pin_to_the_option_set()
247+
{
248+
optionSet.Contains("pin-package").ShouldBeTrue();
249+
}
250+
251+
[Fact]
252+
public void should_add_short_version_of_pin_to_the_option_set()
253+
{
254+
optionSet.Contains("pin").ShouldBeTrue();
255+
}
238256
}
239257

240258
public class when_handling_additional_argument_parsing : ChocolateyInstallCommandSpecsBase

src/chocolatey.tests/infrastructure.app/commands/ChocolateyUpgradeCommandSpecs.cs

+18
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,24 @@ public void should_add_short_version_of_password_to_the_option_set()
217217
{
218218
optionSet.Contains("p").ShouldBeTrue();
219219
}
220+
221+
[Fact]
222+
public void should_add_pin_to_the_option_set()
223+
{
224+
optionSet.Contains("pinpackage").ShouldBeTrue();
225+
}
226+
227+
[Fact]
228+
public void should_add_long_version_of_pin_to_the_option_set()
229+
{
230+
optionSet.Contains("pin-package").ShouldBeTrue();
231+
}
232+
233+
[Fact]
234+
public void should_add_short_version_of_pin_to_the_option_set()
235+
{
236+
optionSet.Contains("pin").ShouldBeTrue();
237+
}
220238
}
221239

222240
public class when_handling_additional_argument_parsing : ChocolateyUpgradeCommandSpecsBase

src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs

+9-5
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
108108
{
109109
if (option != null) configuration.Features.AllowEmptyChecksums = true;
110110
})
111-
.Add("allowemptychecksumsecure|allowemptychecksumssecure|allow-empty-checksums-secure",
111+
.Add("allowemptychecksumsecure|allowemptychecksumssecure|allow-empty-checksums-secure",
112112
"Allow Empty Checksums Secure - Allow packages to have empty checksums for downloaded resources from secure locations (HTTPS). Overrides the default feature '{0}' set to '{1}'. Available in 0.10.0+.".format_with(ApplicationParameters.Features.AllowEmptyChecksumsSecure, configuration.Features.AllowEmptyChecksumsSecure.to_string()),
113113
option =>
114114
{
@@ -146,20 +146,20 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
146146
configuration.Features.UsePackageExitCodes = false;
147147
}
148148
})
149-
.Add("usepackagecodes|usepackageexitcodes|use-package-codes|use-package-exit-codes",
149+
.Add("usepackagecodes|usepackageexitcodes|use-package-codes|use-package-exit-codes",
150150
"UsePackageExitCodes - Package scripts can provide exit codes. Use those for choco's exit code when non-zero (this value can come from a dependency package). Chocolatey defines valid exit codes as 0, 1605, 1614, 1641, 3010. Overrides the default feature '{0}' set to '{1}'. Available in 0.9.10+.".format_with(ApplicationParameters.Features.UsePackageExitCodes, configuration.Features.UsePackageExitCodes.to_string()),
151151
option => configuration.Features.UsePackageExitCodes = option != null
152152
)
153-
.Add("stoponfirstfailure|stop-on-first-failure|stop-on-first-package-failure",
153+
.Add("stoponfirstfailure|stop-on-first-failure|stop-on-first-package-failure",
154154
"Stop On First Package Failure - stop running install, upgrade or uninstall on first package failure instead of continuing with others. Overrides the default feature '{0}' set to '{1}'. Available in 0.10.4+.".format_with(ApplicationParameters.Features.StopOnFirstPackageFailure, configuration.Features.StopOnFirstPackageFailure.to_string()),
155155
option => configuration.Features.StopOnFirstPackageFailure = option != null
156156
)
157-
.Add("exitwhenrebootdetected|exit-when-reboot-detected",
157+
.Add("exitwhenrebootdetected|exit-when-reboot-detected",
158158
"Exit When Reboot Detected - Stop running install, upgrade, or uninstall when a reboot request is detected. Requires '{0}' feature to be turned on. Will exit with either {1} or {2}. Overrides the default feature '{3}' set to '{4}'. Available in 0.10.12+.".format_with
159159
(ApplicationParameters.Features.UsePackageExitCodes, ApplicationParameters.ExitCodes.ErrorFailNoActionReboot, ApplicationParameters.ExitCodes.ErrorInstallSuspend, ApplicationParameters.Features.ExitOnRebootDetected, configuration.Features.ExitOnRebootDetected.to_string()),
160160
option => configuration.Features.ExitOnRebootDetected = option != null
161161
)
162-
.Add("ignoredetectedreboot|ignore-detected-reboot",
162+
.Add("ignoredetectedreboot|ignore-detected-reboot",
163163
"Ignore Detected Reboot - Ignore any detected reboots if found. Overrides the default feature '{0}' set to '{1}'. Available in 0.10.12+.".format_with
164164
(ApplicationParameters.Features.ExitOnRebootDetected, configuration.Features.ExitOnRebootDetected.to_string()),
165165
option =>
@@ -179,6 +179,10 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
179179
configuration.Features.UsePackageRepositoryOptimizations = false;
180180
}
181181
})
182+
.Add("pin|pinpackage|pin-package",
183+
"Pin Package - Add a pin to the package after install. Available in 1.2.0+",
184+
option => configuration.PinPackage = option != null
185+
)
182186
;
183187

184188
//todo: #770 package name can be a url / installertype

src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs

+15-11
Original file line numberDiff line numberDiff line change
@@ -152,23 +152,23 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
152152
configuration.Features.UsePackageExitCodes = false;
153153
}
154154
})
155-
.Add("usepackagecodes|usepackageexitcodes|use-package-codes|use-package-exit-codes",
155+
.Add("usepackagecodes|usepackageexitcodes|use-package-codes|use-package-exit-codes",
156156
"UsePackageExitCodes - Package scripts can provide exit codes. Use those for choco's exit code when non-zero (this value can come from a dependency package). Chocolatey defines valid exit codes as 0, 1605, 1614, 1641, 3010. Overrides the default feature '{0}' set to '{1}'. Available in 0.9.10+.".format_with(ApplicationParameters.Features.UsePackageExitCodes, configuration.Features.UsePackageExitCodes.to_string()),
157157
option => configuration.Features.UsePackageExitCodes = option != null
158158
)
159-
.Add("except=",
159+
.Add("except=",
160160
"Except - a comma-separated list of package names that should not be upgraded when upgrading 'all'. Overrides the configuration setting '{0}' set to '{1}'. Available in 0.9.10+.".format_with(ApplicationParameters.ConfigSettings.UpgradeAllExceptions, configuration.UpgradeCommand.PackageNamesToSkip.to_string()),
161161
option => configuration.UpgradeCommand.PackageNamesToSkip = option.remove_surrounding_quotes()
162162
)
163-
.Add("stoponfirstfailure|stop-on-first-failure|stop-on-first-package-failure",
163+
.Add("stoponfirstfailure|stop-on-first-failure|stop-on-first-package-failure",
164164
"Stop On First Package Failure - stop running install, upgrade or uninstall on first package failure instead of continuing with others. Overrides the default feature '{0}' set to '{1}'. Available in 0.10.4+.".format_with(ApplicationParameters.Features.StopOnFirstPackageFailure, configuration.Features.StopOnFirstPackageFailure.to_string()),
165165
option => configuration.Features.StopOnFirstPackageFailure = option != null
166166
)
167-
.Add("skip-if-not-installed|only-upgrade-installed|skip-when-not-installed",
167+
.Add("skip-if-not-installed|only-upgrade-installed|skip-when-not-installed",
168168
"Skip Packages Not Installed - if a package is not installed, do not install it during the upgrade process. Overrides the default feature '{0}' set to '{1}'. Available in 0.10.12+.".format_with(ApplicationParameters.Features.SkipPackageUpgradesWhenNotInstalled, configuration.Features.SkipPackageUpgradesWhenNotInstalled.to_string()),
169169
option => configuration.Features.SkipPackageUpgradesWhenNotInstalled = option != null
170170
)
171-
.Add("install-if-not-installed",
171+
.Add("install-if-not-installed",
172172
"Install Missing Packages When Not Installed - if a package is not installed, install it as part of running upgrade (typically default behavior). Overrides the default feature '{0}' set to '{1}'. Available in 0.10.12+.".format_with(ApplicationParameters.Features.SkipPackageUpgradesWhenNotInstalled, configuration.Features.SkipPackageUpgradesWhenNotInstalled.to_string()),
173173
option =>
174174
{
@@ -177,28 +177,28 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
177177
configuration.Features.SkipPackageUpgradesWhenNotInstalled = false;
178178
}
179179
})
180-
.Add("exclude-pre|exclude-prerelease|exclude-prereleases",
180+
.Add("exclude-pre|exclude-prerelease|exclude-prereleases",
181181
"Exclude Prerelease - Should prerelease be ignored for upgrades? Will be ignored if you pass `--pre`. Available in 0.10.4+.",
182182
option => configuration.UpgradeCommand.ExcludePrerelease = option != null
183183
)
184-
.Add("userememberedargs|userememberedarguments|userememberedoptions|use-remembered-args|use-remembered-arguments|use-remembered-options",
184+
.Add("userememberedargs|userememberedarguments|userememberedoptions|use-remembered-args|use-remembered-arguments|use-remembered-options",
185185
"Use Remembered Options for Upgrade - use the arguments and options used during install for upgrade. Does not override arguments being passed at runtime. Overrides the default feature '{0}' set to '{1}'. Available in 0.10.4+.".format_with(ApplicationParameters.Features.UseRememberedArgumentsForUpgrades, configuration.Features.UseRememberedArgumentsForUpgrades.to_string()),
186186
option =>
187187
{
188188
if (option != null) configuration.Features.UseRememberedArgumentsForUpgrades = true;
189189
})
190-
.Add("ignorerememberedargs|ignorerememberedarguments|ignorerememberedoptions|ignore-remembered-args|ignore-remembered-arguments|ignore-remembered-options",
190+
.Add("ignorerememberedargs|ignorerememberedarguments|ignorerememberedoptions|ignore-remembered-args|ignore-remembered-arguments|ignore-remembered-options",
191191
"Ignore Remembered Options for Upgrade - ignore the arguments and options used during install for upgrade. Overrides the default feature '{0}' set to '{1}'. Available in 0.10.4+.".format_with(ApplicationParameters.Features.UseRememberedArgumentsForUpgrades, configuration.Features.UseRememberedArgumentsForUpgrades.to_string()),
192192
option =>
193193
{
194194
if (option != null) configuration.Features.UseRememberedArgumentsForUpgrades = false;
195195
})
196-
.Add("exitwhenrebootdetected|exit-when-reboot-detected",
196+
.Add("exitwhenrebootdetected|exit-when-reboot-detected",
197197
"Exit When Reboot Detected - Stop running install, upgrade, or uninstall when a reboot request is detected. Requires '{0}' feature to be turned on. Will exit with either {1} or {2}. Overrides the default feature '{3}' set to '{4}'. Available in 0.10.12+.".format_with
198198
(ApplicationParameters.Features.UsePackageExitCodes, ApplicationParameters.ExitCodes.ErrorFailNoActionReboot, ApplicationParameters.ExitCodes.ErrorInstallSuspend, ApplicationParameters.Features.ExitOnRebootDetected, configuration.Features.ExitOnRebootDetected.to_string()),
199199
option => configuration.Features.ExitOnRebootDetected = option != null
200200
)
201-
.Add("ignoredetectedreboot|ignore-detected-reboot",
201+
.Add("ignoredetectedreboot|ignore-detected-reboot",
202202
"Ignore Detected Reboot - Ignore any detected reboots if found. Overrides the default feature '{0}' set to '{1}'. Available in 0.10.12+.".format_with
203203
(ApplicationParameters.Features.ExitOnRebootDetected, configuration.Features.ExitOnRebootDetected.to_string()),
204204
option =>
@@ -208,7 +208,7 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
208208
configuration.Features.ExitOnRebootDetected = false;
209209
}
210210
})
211-
.Add("disable-repository-optimizations|disable-package-repository-optimizations",
211+
.Add("disable-repository-optimizations|disable-package-repository-optimizations",
212212
"Disable Package Repository Optimizations - Do not use optimizations for reducing bandwidth with repository queries during package install/upgrade/outdated operations. Should not generally be used, unless a repository needs to support older methods of query. When disabled, this makes queries similar to the way they were done in Chocolatey v0.10.11 and before. Overrides the default feature '{0}' set to '{1}'. Available in 0.10.14+.".format_with
213213
(ApplicationParameters.Features.UsePackageRepositoryOptimizations, configuration.Features.UsePackageRepositoryOptimizations.to_string()),
214214
option =>
@@ -218,6 +218,10 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
218218
configuration.Features.UsePackageRepositoryOptimizations = false;
219219
}
220220
})
221+
.Add("pin|pinpackage|pin-package",
222+
"Pin Package - Add a pin to the package after upgrade. Available in 1.2.0+",
223+
option => configuration.PinPackage = option != null
224+
)
221225
;
222226
}
223227

src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs

+1
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ private void append_output(StringBuilder propertyValues, string append)
235235
public string DownloadChecksum64 { get; set; }
236236
public string DownloadChecksumType { get; set; }
237237
public string DownloadChecksumType64 { get; set; }
238+
public bool PinPackage { get; set; }
238239

239240
/// <summary>
240241
/// Configuration values provided by choco.

src/chocolatey/infrastructure.app/configuration/PackagesConfigFilePackageSetting.cs

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ public sealed class PackagesConfigFilePackageSetting
5959
[XmlAttribute(AttributeName = "disabled")]
6060
public bool Disabled { get; set; }
6161

62+
[XmlAttribute(AttributeName = "pinPackage")]
63+
public bool PinPackage { get; set; }
64+
6265
[System.ComponentModel.DefaultValue(-1)]
6366
[XmlAttribute(AttributeName = "executionTimeout")]
6467
public int ExecutionTimeout { get; set; }

src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ public virtual void handle_package_result(PackageResult packageResult, Chocolate
408408
handle_extension_packages(config, packageResult);
409409
handle_template_packages(config, packageResult);
410410
pkgInfo.Arguments = capture_arguments(config, packageResult);
411+
pkgInfo.IsPinned = config.PinPackage;
411412
}
412413

413414
var toolsLocation = Environment.GetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyToolsLocation);
@@ -737,8 +738,9 @@ private IEnumerable<ChocolateyConfiguration> get_packages_from_config(string pac
737738
if (pkgSettings.ApplyPackageParametersToDependencies) packageConfig.ApplyPackageParametersToDependencies = true;
738739
SourceType sourceType;
739740
if (Enum.TryParse(pkgSettings.Source, true, out sourceType)) packageConfig.SourceType = sourceType;
741+
if (pkgSettings.PinPackage) packageConfig.PinPackage = true;
740742
if (pkgSettings.Force) packageConfig.Force = true;
741-
packageConfig.CommandExecutionTimeoutSeconds = pkgSettings.ExecutionTimeout == -1 ? packageConfig.ExecutionTimeout : pkgSettings.CommandExecutionTimeoutSeconds;
743+
packageConfig.CommandExecutionTimeoutSeconds = pkgSettings.ExecutionTimeout == -1 ? packageConfig.CommandExecutionTimeoutSeconds : pkgSettings.ExecutionTimeout;
742744
if (pkgSettings.Prerelease) packageConfig.Prerelease = true;
743745
if (pkgSettings.OverrideArguments) packageConfig.OverrideArguments = true;
744746
if (pkgSettings.NotSilent) packageConfig.NotSilent = true;

0 commit comments

Comments
 (0)