rhg: Colored output is not supported
authorSimon Sapin <simon.sapin@octobus.net>
Tue, 09 Nov 2021 19:28:13 +0100
changeset 48340 d71b9902e2de
parent 48339 a2e278b5e265
child 48341 51f26c8088b2
rhg: Colored output is not supported Fallback if it is requested explicitly. The default is documented as use color "whenever it seems possible". rhg proceeds without color in that case. Differential Revision: https://phab.mercurial-scm.org/D11762
rust/rhg/src/main.rs
tests/test-status-color.t
--- a/rust/rhg/src/main.rs	Tue Nov 09 19:09:57 2021 +0100
+++ b/rust/rhg/src/main.rs	Tue Nov 09 19:28:13 2021 +0100
@@ -28,7 +28,7 @@
     repo: Result<&Repo, &NoRepoInCwdError>,
     config: &Config,
 ) -> Result<(), CommandError> {
-    check_unsupported(config)?;
+    check_unsupported(config, ui)?;
 
     let app = App::new("rhg")
         .global_setting(AppSettings::AllowInvalidUtf8)
@@ -617,7 +617,10 @@
     }
 }
 
-fn check_unsupported(config: &Config) -> Result<(), CommandError> {
+fn check_unsupported(
+    config: &Config,
+    ui: &ui::Ui,
+) -> Result<(), CommandError> {
     check_extensions(config)?;
 
     if std::env::var_os("HG_PENDING").is_some() {
@@ -634,5 +637,11 @@
         Err(CommandError::unsupported("[decode] config"))?
     }
 
+    if let Some(color) = config.get(b"ui", b"color") {
+        if (color == b"always" || color == b"debug") && !ui.plain() {
+            Err(CommandError::unsupported("colored output"))?
+        }
+    }
+
     Ok(())
 }
--- a/tests/test-status-color.t	Tue Nov 09 19:09:57 2021 +0100
+++ b/tests/test-status-color.t	Tue Nov 09 19:28:13 2021 +0100
@@ -1,7 +1,3 @@
-TODO: fix rhg bugs that make this test fail when status is enabled
-  $ unset RHG_STATUS
-
-
   $ cat <<EOF >> $HGRCPATH
   > [ui]
   > color = always