diff --git a/src/client/opamCommands.ml b/src/client/opamCommands.ml index b22616feaa1..b422c12dc55 100644 --- a/src/client/opamCommands.ml +++ b/src/client/opamCommands.ml @@ -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 @@ -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 @@ -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 @@ -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 *)