diff --git a/src/diff_util.rs b/src/diff_util.rs index ae94df395..4b50aa3b4 100644 --- a/src/diff_util.rs +++ b/src/diff_util.rs @@ -33,6 +33,7 @@ use crate::cli_util::{CommandError, WorkspaceCommandHelper}; use crate::formatter::Formatter; #[derive(clap::Args, Clone, Debug)] +#[command(group(clap::ArgGroup::new("diff-format").args(&["git", "color_words"])))] pub struct DiffFormatArgs { /// For each path, show only whether it was modified, added, or removed #[arg(long, short)] diff --git a/tests/test_diff_command.rs b/tests/test_diff_command.rs index f29bf410b..57cec5475 100644 --- a/tests/test_diff_command.rs +++ b/tests/test_diff_command.rs @@ -101,6 +101,22 @@ fn test_diff_basic() { "###); } +#[test] +fn test_diff_bad_args() { + let test_env = TestEnvironment::default(); + test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); + let repo_path = test_env.env_root().join("repo"); + + let stderr = test_env.jj_cmd_cli_error(&repo_path, &["diff", "--color-words", "--git"]); + insta::assert_snapshot!(stderr, @r###" + error: The argument '--color-words' cannot be used with '--git' + + Usage: jj diff --color-words [PATHS]... + + For more information try '--help' + "###); +} + #[test] fn test_diff_relative_paths() { let test_env = TestEnvironment::default(); diff --git a/tests/test_log_command.rs b/tests/test_log_command.rs index dc45dea61..7df8c8a5b 100644 --- a/tests/test_log_command.rs +++ b/tests/test_log_command.rs @@ -165,8 +165,8 @@ fn test_log_with_or_without_diff() { +foo "###); - // Both formats enabled if `--git` and `--color-words` are explicitly specified - let stdout = test_env.jj_cmd_success( + // Cannot use both `--git` and `--color-words` + let stderr = test_env.jj_cmd_cli_error( &repo_path, &[ "log", @@ -178,28 +178,12 @@ fn test_log_with_or_without_diff() { "--color-words", ], ); - insta::assert_snapshot!(stdout, @r###" - a new commit - diff --git a/file1 b/file1 - index 257cc5642c...3bd1f0e297 100644 - --- a/file1 - +++ b/file1 - @@ -1,1 +1,2 @@ - foo - +bar - Modified regular file file1: - 1 1: foo - 2: bar - add a file - diff --git a/file1 b/file1 - new file mode 100644 - index 0000000000..257cc5642c - --- /dev/null - +++ b/file1 - @@ -1,0 +1,1 @@ - +foo - Added regular file file1: - 1: foo + insta::assert_snapshot!(stderr, @r###" + error: The argument '--git' cannot be used with '--color-words' + + Usage: jj log --template