Skip to content

Commit

Permalink
repo: set-url and add with no-action
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbou committed Nov 24, 2021
1 parent 87fb868 commit eaa01ae
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/client/opamCommands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2097,7 +2097,13 @@ let repository cli =
otherwise be used to explicitly set the repository list at once."
Arg.(int) 1
in
let repository global_options command kind short scope rank params () =
let no_action =
mk_flag ~cli (cli_from cli2_2) ["n"; "no-action"]
"Do not automatically update when adding or changin repository url. \
You must update afterwards"
in
let repository global_options command kind short scope rank params
no_action () =
apply_global_options cli global_options;
let global = List.mem `Default scope in
let command, params, rank = match command, params, rank with
Expand Down Expand Up @@ -2170,13 +2176,14 @@ let repository cli =
in
OpamRepositoryState.with_ `Lock_write gt (fun rt ->
let rt = OpamRepositoryCommand.add rt name url trust_anchors in
let failed, rt =
OpamRepositoryCommand.update_with_auto_upgrade rt [name]
in
if failed <> [] then
(OpamRepositoryState.drop @@ OpamRepositoryCommand.remove rt name;
OpamConsole.error_and_exit `Sync_error
"Initial repository fetch failed"));
if not no_action then
let failed, rt =
OpamRepositoryCommand.update_with_auto_upgrade rt [name]
in
if failed <> [] then
(OpamRepositoryState.drop @@ OpamRepositoryCommand.remove rt name;
OpamConsole.error_and_exit `Sync_error
"Initial repository fetch failed"));
OpamGlobalState.drop @@ OpamRepositoryCommand.update_selection gt ~global
~switches (update_repos name);
if scope = [`Current_switch] then
Expand Down Expand Up @@ -2241,9 +2248,8 @@ let repository cli =
OpamGlobalState.with_ `Lock_none @@ fun gt ->
OpamRepositoryState.with_ `Lock_write gt @@ fun rt ->
let rt = OpamRepositoryCommand.set_url rt name url trust_anchors in
let _failed, _rt =
OpamRepositoryCommand.update_with_auto_upgrade rt [name]
in
if not no_action then
ignore @@ OpamRepositoryCommand.update_with_auto_upgrade rt [name];
`Ok ()
| Some `set_repos, names ->
let names = List.map OpamRepositoryName.of_string names in
Expand Down Expand Up @@ -2288,7 +2294,7 @@ let repository cli =
mk_command_ret ~cli cli_original "repository" ~doc ~man
Term.(const repository $global_options cli $command
$repo_kind_flag cli cli_original $print_short_flag cli cli_original
$scope $rank $params)
$scope $rank $params $no_action)


(* SWITCH *)
Expand Down

0 comments on commit eaa01ae

Please sign in to comment.