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

Add support for "opam switch -" (go to previous switch) #4910

Merged
merged 4 commits into from
Feb 17, 2022

Conversation

kit-ty-kate
Copy link
Member

This implements #4688 with the same behaviour as git switch -

cc @craigfe

@kit-ty-kate kit-ty-kate linked an issue Nov 13, 2021 that may be closed by this pull request
@kit-ty-kate kit-ty-kate added this to the 2.2.0~alpha milestone Nov 13, 2021
Copy link
Collaborator

@rjbou rjbou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
Some modifications suggested, and some doc missing (manpage, website).
Also, should we add an format upgrade function to convert already present switches named -, in case they exist? Or we can assume that they don't exist (it wasn't forbidden, so it can exist).

src/format/opamFile.ml Outdated Show resolved Hide resolved
src/format/opamFile.ml Outdated Show resolved Hide resolved
src/client/opamSwitchCommand.ml Outdated Show resolved Hide resolved
tests/reftests/switch-set.test Outdated Show resolved Hide resolved
@kit-ty-kate kit-ty-kate force-pushed the prev-switch branch 3 times, most recently from abf9641 to 47c7928 Compare November 16, 2021 15:39
@kit-ty-kate
Copy link
Member Author

All done. The switch name - now does not interfere with opam switch -. It is still possible to create such a switch and to set it (using either opam switch set - or opam switch --cli=2.1 -) so no issues converting.

I’m still trying to figure out the manpage/doc situation but other than that this should be ready

@rjbou
Copy link
Collaborator

rjbou commented Nov 16, 2021

On non avoiding - as a switch name, we loose correspondence between opam switch x and opam switch set x. It's not an issue itself, but we need it to be clear on switch doc (and later on release doc). Old behavior is well kept with the cli check.

@kit-ty-kate
Copy link
Member Author

On non avoiding - as a switch name, we loose correspondence between opam switch x and opam switch set x. It's not an issue itself, but we need it to be clear on switch doc (and later on release doc). Old behavior is well kept with the cli check.

is the new manpage entry clear enough?

@rjbou
Copy link
Collaborator

rjbou commented Nov 16, 2021

It is clear, i wrote the comment before you last push :)

@kit-ty-kate kit-ty-kate force-pushed the prev-switch branch 2 times, most recently from d652baf to c141311 Compare November 16, 2021 20:11
@rjbou
Copy link
Collaborator

rjbou commented Nov 18, 2021

We need to check for opam root, but otherwise, lgtm!

@kit-ty-kate kit-ty-kate force-pushed the prev-switch branch 2 times, most recently from 2688441 to 022a7a1 Compare November 19, 2021 10:01
@rjbou
Copy link
Collaborator

rjbou commented Nov 19, 2021

I need to rework the opam root test first, to make it no opamroot bump specific

@rjbou rjbou added the PR: QUEUED Pending pull request, waiting for other work to be merged or closed label Nov 22, 2021
@rjbou
Copy link
Collaborator

rjbou commented Nov 22, 2021

Reworked in #4913 & #4926 for the bump

@AltGr
Copy link
Member

AltGr commented Dec 22, 2021

On non avoiding - as a switch name, we loose correspondence between opam switch x and opam switch set x. It's not an issue itself, but we need it to be clear on switch doc (and later on release doc). Old behavior is well kept with the cli check.

that correspondance was already not there (which is why set still exists), you could have switches called create or set.

@AltGr
Copy link
Member

AltGr commented Dec 22, 2021

LGTM; I can suggest an idea to avoid having to bump the format though: order the installed-switches: field by order of most recently used first. This would be fully backwards-compatible and consistent, and could even maybe find other uses.

@AltGr AltGr force-pushed the prev-switch branch 2 times, most recently from 842075d to ac19c21 Compare December 22, 2021 14:18
@AltGr
Copy link
Member

AltGr commented Dec 22, 2021

Couldn't resist and tried an implementation :)
There are differences though, I cut the patch in 2 to make the test difference obvious in ac19c21

src/format/opamFile.ml Outdated Show resolved Hide resolved
src/format/opamFile.ml Outdated Show resolved Hide resolved
tests/reftests/switch-set.test Show resolved Hide resolved
@kit-ty-kate kit-ty-kate removed the PR: QUEUED Pending pull request, waiting for other work to be merged or closed label Feb 15, 2022
src/format/opamFile.ml Outdated Show resolved Hide resolved
src/format/opamFile.ml Outdated Show resolved Hide resolved
@rjbou rjbou self-requested a review February 17, 2022 00:31
kit-ty-kate and others added 4 commits February 17, 2022 16:10
Co-authored-by: Raja Boujbel <raja.boujbel@ocamlpro.com>
Use ordering of installed-switches instead of a new field

This avoids bumping the file version.

There are small differences in semantics though, as shown in the tests:
- after switching twice to the same switch, `opam switch -` now still gets you
  to the one before that
- it gets you to the 'last-known-good' switch, even if the last one was removed

I would argue that this new behaviour is ok, if not better.

Add a specific error in case the previous switch no longer exists

Co-authored-by: Louis Gesbert <louis.gesbert@ocamlpro.com>
Co-authored-by: R. Boujbel <rjbou@ocamlpro.com>
Check that switches with name "-" do not interfere with the "go to previous switch" feature

reftests: add in switch-set some previous switch log, local switch and removed switch tests
@kit-ty-kate kit-ty-kate merged commit 4cffd41 into ocaml:master Feb 17, 2022
@kit-ty-kate kit-ty-kate deleted the prev-switch branch February 17, 2022 19:49
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.

Feature request: support opam switch -
3 participants