Skip to content

Commit

Permalink
Check that the repositories given to "opam repository remove" actuall…
Browse files Browse the repository at this point in the history
…y exist
  • Loading branch information
kit-ty-kate committed Aug 12, 2024
1 parent ebbcea2 commit e10201b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ users)
## Lint

## Repository
* Check that the repositories given to `opam repository remove` actually exist [#5014 @kit-ty-kate - fixes #5012]

## Lock

Expand Down
20 changes: 19 additions & 1 deletion src/client/opamCommands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2418,13 +2418,26 @@ let repository cli =
`Ok ()
| Some `remove, names ->
let names = List.map OpamRepositoryName.of_string names in
let rm = List.filter (fun n -> not (List.mem n names)) in
let full_wipe = List.mem `All scope in
let global = global || full_wipe in
let unknown_repos = ref (if full_wipe then [] else names) in
let rm =
List.filter (fun n ->
let seen =
List.exists (fun n' -> OpamRepositoryName.equal n n') names
in
if seen && not full_wipe then
unknown_repos :=
List.filter
(fun n' -> not (OpamRepositoryName.equal n n'))
!unknown_repos;
not seen)
in
let gt =
OpamRepositoryCommand.update_selection gt
~global ~switches:switches rm
in
let unknown_repos = !unknown_repos in
if full_wipe then
OpamRepositoryState.with_ `Lock_write gt @@ fun rt ->
check_for_repos rt names
Expand All @@ -2437,6 +2450,11 @@ let repository cli =
"Repositories removed from the selections of switch %s. \
Use '--all' to forget about them altogether.\n"
(OpamSwitch.to_string (OpamStateConfig.get_switch ()));
List.iter (fun repo ->
OpamConsole.warning "Repository '%s' not found in the \
current switch, ignoring"
(OpamRepositoryName.to_string repo))
unknown_repos;
`Ok ()
| Some `add, [name] ->
let name = OpamRepositoryName.of_string name in
Expand Down
2 changes: 2 additions & 0 deletions tests/reftests/repository.test
Original file line number Diff line number Diff line change
Expand Up @@ -623,10 +623,12 @@ to-many-commits git+file://${BASEDIR}/TMCS repos(1/3)
3 oper file://${BASEDIR}/OPER3
### opam repository remove does-not-exist
Repositories removed from the selections of switch repos. Use '--all' to forget about them altogether.
[WARNING] Repository 'does-not-exist' not found in the current switch, ignoring
### opam repository remove does-not-exist --all
[WARNING] No configured repositories by these names found: does-not-exist
### opam repository remove does-not-exist oper
Repositories removed from the selections of switch repos. Use '--all' to forget about them altogether.
[WARNING] Repository 'does-not-exist' not found in the current switch, ignoring
### opam repository remove does-not-exist repo2 --all
[WARNING] No configured repositories by these names found: does-not-exist
### opam repository --all
Expand Down

0 comments on commit e10201b

Please sign in to comment.