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

Fix crash when prefix of "lock" subcommand is used #381

Merged
merged 1 commit into from
Apr 17, 2023
Merged
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
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
- Fix a failure when using opam-monorepo with an opam 2.2 root
(#379, @kit-ty-kate)

- Fix assertion failure when prefix of "lock" subcommand is used (#381,
@gridbugs)

### Removed

### Security
Expand Down
2 changes: 1 addition & 1 deletion cli/lock.ml
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ let extract_source_config ~adjustment ~opam_monorepo_cwd ~opam_files

let raw_cli_args () =
match Array.to_list Sys.argv with
| _bin :: "lock" :: args -> args
| _bin :: prefix :: args when String.starts_with ~prefix "lock" -> args
Copy link
Member

Choose a reason for hiding this comment

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

I think this would lead to a weird case where opam-monorepo locksmith goes into this case.

I am somewhat confused how you got into this place, since I would've expected opam-monorepo locksmith not resolving to this module to start with.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It will only match prefixes of "lock", not strings which "lock" is a prefix of. cmdliner accepts prefixes of subcommands already. This code here is a sanity check that the command was a opam monorepo lock subcommand when saving the command to the lockfile.

Copy link
Member

@Leonidas-from-XIV Leonidas-from-XIV Apr 14, 2023

Choose a reason for hiding this comment

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

Ah, you're right, I've misread the code. Honestly, I think the previous code is fine and we/Cmdliner should not accept prefix matches. If the user uses opam monorepo lo and we introduce a new command that starts with lo then suddenly things that worked don't anymore because it is impossible to disambiguate. Which can be annoying in e.g. scripts like the CI.

Edit: Heh, we already have a conflict in l, so lo is required anyway.

| _ -> assert false

let run (`Root root) (`Recurse_opam recurse) (`Build_only build_only)
Expand Down