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

(#2603) Export pin status #2618

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

TheCakeIsNaOH
Copy link
Member

@TheCakeIsNaOH TheCakeIsNaOH commented Mar 6, 2022

Description Of Changes

This adds the ability for the export command to include pins in the
exported file. They will be exported if --include-arguments is
specified, but can be excluded with --exclude-pins.

Motivation and Context

See #2603

Testing

  1. Run .\choco.exe install iperf2 wget --allow-unofficial
  2. Run .\choco.exe pin add -n iperf2 --allow-unofficial
  3. Run .\choco.exe export --include-arguments --allow-unofficial
  4. Check that the exported packages.config includes <package id="iperf2" pinPackage="true" />
  5. Run .\choco.exe export --include-argument --exclude-pins --allow-unofficial
  6. Check that the export packages.config does not include pinPackage for iperf2

Change Types Made

  • Bug fix (non-breaking change)
  • Feature / Enhancement (non-breaking change)
  • Breaking change (fix or feature that could cause existing functionality to change)

Related Issue

Fixes #2603
Depends on #2506 (and thus #3003 as well)

Change Checklist

  • Requires a change to the documentation
  • Documentation has been updated
  • Tests to cover my changes, have been added
  • All new and existing tests passed.
  • N/A PowerShell v2 compatibility checked.

@coveralls
Copy link

coveralls commented Jun 27, 2022

Coverage Status

Coverage increased (+0.4%) to 27.945% when pulling 290ac65 on TheCakeIsNaOH:export-pin into d08d1f6 on chocolatey:develop.

@TheCakeIsNaOH TheCakeIsNaOH marked this pull request as draft September 23, 2022 04:53
@TheCakeIsNaOH TheCakeIsNaOH marked this pull request as ready for review September 24, 2022 22:52
@TheCakeIsNaOH TheCakeIsNaOH force-pushed the export-pin branch 2 times, most recently from 0befa46 to 90132e7 Compare December 23, 2022 01:22
@TheCakeIsNaOH TheCakeIsNaOH force-pushed the export-pin branch 2 times, most recently from e378b21 to b33cdad Compare January 13, 2023 15:26
@TheCakeIsNaOH TheCakeIsNaOH marked this pull request as draft January 28, 2023 04:16
@aetonsi
Copy link

aetonsi commented Aug 8, 2023

Is there any news on this? It is essential..
An export command that exports something that cannot be used to recreate the exact environment, is not very useful..
One could simply do:

  • ( choco list | select -skip 1 | select -skiplast 1 | % { ($_ -split ' ')[0] } ) -join ' ' >choco.list: to get a space-separated list of packages
  • choco install $(cat choco.list): to reinstall all packages with a single choco call

So choco export is incomplete without install arguments and pins and anything else needed to replicate an environment

@pauby
Copy link
Member

pauby commented Aug 8, 2023

@aetonsi This PR is in draft and no milestone has been targetted for its release.

@TheCakeIsNaOH
Copy link
Member Author

Rebased on top of #3003

@TheCakeIsNaOH TheCakeIsNaOH marked this pull request as ready for review January 10, 2024 00:28
This helps ensure that package IDs are handled in a case
insensitive manner.
This allows overriding of remembered package parameters, install
arguments, cache location and execution timeout during upgrade.
So a user can pass in different package parameters or arguments
without having to completely reinstall the package or turn off
remembered arguments.

Switch arguments cannot be checked, because the lack of a switch
normally would mean that they are just relying on the remembered args
to remember it, so there is no way to determine if an override of the
remembered args is appropriate.
…ration

This adds a new method, GetPackageConfigFromRememberedArguments which
is similar to SetConfigFromRememberedArguments, but operates using a
different method. First, a OptionSet is set up, so only the config
that is passed in is modified, instead of the config that the global
options parser was set with with. Second, it returns the modified
configuration instead of the original configuration, because it is the
local configuration being modified. Third, it has a more general name
and changes log messages to be more general, so it later can more
easily be reused for uninstall and export.

This change fixes remembered arguments when Chocolatey is used as a
library, like in ChocolateyGUI, where the config that is passed to
the install_run method is not necessarily the same config object that
was used to set up the global argument parser.

The downside of using a new commandline parser is that it opens up the
possibility of drift between the upgrade/global arguments and this
added parser. However, this is not an issue because the format of the
saved arguments is known, and any added arguments there would not work
without being added here as well, which would be picked up during
development.
Instead of exporting via building an xml document manually, this
creates a PackagesConfigFilePackageSetting and serializes that to
create the xml document that is saved. This allows for usage of the
same class as is used to read in packages.config files to export
those files.

The reason the various "Specified" members are added to the
PackagesConfigFilePackageSetting class is so if an element is not set
during export, it will not show up at all in the resulting serialized
packages.config file.
This adds the --include-remembered-arguments option which is used to
export any remembered arguments. It reuses the
GetPackageConfigFromRememberedArguments method in the NugetService to
read and parse the remembered arguments.
This adds the ability for the export command to include pins in the
exported file. They will be exported if --include-arguments is
specified, but can be excluded with --exclude-pins.
@ThomasHeinrichSchmidt
Copy link

Will this feature ever become a reality?
I really hope so!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add option to include pinned-state in the choco export command
5 participants