diff --git a/bin/common.ml b/bin/common.ml index 7cfd8d8d3cb..b3c4eb80742 100644 --- a/bin/common.ml +++ b/bin/common.ml @@ -634,6 +634,7 @@ module Builder = struct let default_root_is_cwd t = t.default_root_is_cwd let set_default_root_is_cwd t x = { t with default_root_is_cwd = x } let disable_log_file t = { t with trace_file = None } + let promote t = t.promote let set_promote t v = { t with promote = Some v } let default_target t = t.default_target diff --git a/bin/common.mli b/bin/common.mli index b0cbd5feb46..9510a907bc2 100644 --- a/bin/common.mli +++ b/bin/common.mli @@ -45,6 +45,7 @@ module Builder : sig val default_root_is_cwd : t -> bool val set_default_root_is_cwd : t -> bool -> t val disable_log_file : t -> t + val promote : t -> Dune_engine.Clflags.Promote.t option val set_promote : t -> Dune_engine.Clflags.Promote.t -> t val default_target : t -> Arg.Dep.t val term : t Cmdliner.Term.t diff --git a/bin/fmt.ml b/bin/fmt.ml index 71813604f15..d06850fe2f3 100644 --- a/bin/fmt.ml +++ b/bin/fmt.ml @@ -71,6 +71,16 @@ let command = them. This takes precedence over auto-promote as that flag is assumed \ for this command.")) in + let () = + match Common.Builder.promote builder with + | Some Never -> + User_error.raise + [ Pp.text + "The --disable-promotion flag is not applicable to `dune fmt`. Use \ + --preview to display formatting changes without applying them." + ] + | _ -> () + in let builder = Common.Builder.set_promote builder (if preview then Never else Automatically) in diff --git a/bin/promotion.ml b/bin/promotion.ml index 2c1fd58ffba..ea6eef5fdac 100644 --- a/bin/promotion.ml +++ b/bin/promotion.ml @@ -79,6 +79,15 @@ module Apply = struct (* CR-someday Alizter: document this option *) Arg.(value & pos_all Arg.path [] & info [] ~docv:"FILE" ~doc:None) in + let () = + match Common.Builder.promote builder with + | Some Dune_engine.Clflags.Promote.Never -> + User_error.raise + [ Pp.text + "The --disable-promotion flag is not applicable to `dune promotion apply`." + ] + | _ -> () + in run ~builder ~exact ~files ;; diff --git a/test/blackbox-tests/test-cases/promote/disable-promotion.t/run.t b/test/blackbox-tests/test-cases/promote/disable-promotion.t/run.t index c3542785aad..f022d8e351d 100644 --- a/test/blackbox-tests/test-cases/promote/disable-promotion.t/run.t +++ b/test/blackbox-tests/test-cases/promote/disable-promotion.t/run.t @@ -16,3 +16,15 @@ now we build without the option and see that they are present: foo.exe exists $ test -f foo.install && echo "foo.install exists" foo.install exists + +dune fmt rejects --disable-promotion: + $ dune fmt --disable-promotion + Error: The --disable-promotion flag is not applicable to `dune fmt`. Use + --preview to display formatting changes without applying them. + [1] + +dune promotion apply rejects --disable-promotion: + $ dune promotion apply --disable-promotion + Error: The --disable-promotion flag is not applicable to `dune promotion + apply`. + [1]