Skip to content

Commit

Permalink
Add opam pin remove --all
Browse files Browse the repository at this point in the history
  • Loading branch information
kit-ty-kate committed Oct 17, 2022
1 parent 203b9f9 commit 4a8f257
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ users)
* [BUG] Fix origin opam file retrieval when opam originate from locked file [#5079 @rjbou - fix #4936]
* [BUG] When reinstalling a package that has a dirty source, if uncommitted changes are the same than the ones stored in opam's cache, opam consider that it is up to date and nothing is updated [4879 @rjbou]
* [BUG] Handle external dependencies when updating switch state pin status (all pins), instead as a post pin action (only when called with `opam pin` [#5047 @rjbou - fix #5046]
* ◈ Add opam pin remove --all to remove all the pinned packages from a switch [#5308 @kit-ty-kate]

## List
* Some optimisations to 'opam list --installable' queries combined with other filters [#4882 @altgr - fix #4311]
Expand Down
20 changes: 18 additions & 2 deletions src/client/opamCommands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3147,6 +3147,10 @@ let pin ?(unpin_only=false) cli =
changes, and may also be used to keep a package that was removed \
upstream."
in
let all =
mk_flag ~cli (cli_from cli2_2) ["all"]
"When unpinning, removes all pins in the given switch."
in
let guess_names kind ?locked ~recurse ?subpath url k =
let found, cleanup =
match OpamUrl.local_dir url with
Expand Down Expand Up @@ -3263,7 +3267,7 @@ let pin ?(unpin_only=false) cli =
let pin
global_options build_options
kind edit no_act dev_repo print_short recurse subpath normalise
with_version current
with_version current all
command params () =
apply_global_options cli global_options;
apply_build_options cli build_options;
Expand All @@ -3280,6 +3284,10 @@ let pin ?(unpin_only=false) cli =
`list
| Some `scan, [url] ->
`scan url
| Some `remove, [] when all ->
`remove_all
| Some `remove, _::_ when all ->
`incorrect
| Some `remove, (_::_ as arg) ->
`remove arg
| Some `edit, [nv] ->
Expand Down Expand Up @@ -3374,6 +3382,14 @@ let pin ?(unpin_only=false) cli =
else
(OpamSwitchState.drop @@ OpamClient.PIN.unpin st ~action to_unpin;
`Ok ())
| `remove_all ->
OpamGlobalState.with_ `Lock_none @@ fun gt ->
OpamSwitchState.with_ `Lock_write gt @@ fun st ->
let to_unpin =
OpamPackage.Set.to_list_map OpamPackage.name (OpamPinned.packages st)
in
OpamSwitchState.drop @@ OpamClient.PIN.unpin st ~action to_unpin;
`Ok ()
| `edit nv ->
(match (fst package) nv with
| `Ok (name, version) ->
Expand Down Expand Up @@ -3471,7 +3487,7 @@ let pin ?(unpin_only=false) cli =
$global_options cli $build_options cli
$kind $edit $no_act $dev_repo $print_short_flag cli cli_original
$recurse cli $subpath cli
$normalise $with_version $current
$normalise $with_version $current $all
$command $params)

(* SOURCE *)
Expand Down
51 changes: 51 additions & 0 deletions tests/reftests/pin.test
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,54 @@ echo "another-inexistant" "inexistant"
-> installed qux.dev
-> installed bar.dev
Done.
### : Test opam pin remove --all
### OPAMNODEPEXTS=1
### opam pin
bar.dev rsync file://${BASEDIR}/bar
foo.1 local definition
nip.dev rsync file://${BASEDIR}/nip
qux.dev rsync file://${BASEDIR}/qux
### opam pin remove --no-action --all
Ok, qux is no longer pinned to file://${BASEDIR}/qux (version dev)
Ok, nip is no longer pinned to file://${BASEDIR}/nip (version dev)
Ok, foo is no longer pinned locally (version 1)
Ok, bar is no longer pinned to file://${BASEDIR}/bar (version dev)
### opam pin
### opam pin ./bar
The following additional pinnings are required by bar.dev:
- qux.dev at file://${BASEDIR}/qux
Pin and install them? [y/n] y
[qux.dev] synchronised (no changes)
qux is now pinned to file://${BASEDIR}/qux (version dev)
bar is now pinned to file://${BASEDIR}/bar (version dev)

Already up-to-date.
Nothing to do.
### opam pin --current foo
foo is now pinned locally (version 1)
### opam pin
bar.dev rsync file://${BASEDIR}/bar
foo.1 local definition
qux.dev rsync file://${BASEDIR}/qux
### opam pin remove --all foo
opam: opam.exe: Too many arguments.
Usage: opam.exe pin [OPTION]... remove NAMES...|TARGET

# Return code 2 #
### opam pin remove --all
Ok, qux is no longer pinned to file://${BASEDIR}/qux (version dev)
Ok, foo is no longer pinned locally (version 1)
Ok, bar is no longer pinned to file://${BASEDIR}/bar (version dev)
[WARNING] Opam packages bar.dev and qux.dev depend on the following system packages that are no longer installed: another-inexistant inexistant
The following actions will be performed:
=== remove 3 packages
- remove bar dev
- remove foo 1
- remove qux dev

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> removed bar.dev
-> removed foo.1
-> removed qux.dev
Done.
### opam pin

0 comments on commit 4a8f257

Please sign in to comment.