diff --git a/CHANGELOG.md b/CHANGELOG.md index c627ca9ef0..16792f19e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -106,6 +106,9 @@ No code changes (fixing Rust `Cargo.toml` stuff). defined template names when no argument is given, assisting the user in making a selection. +* `ui.default-command` now accepts multiple string arguments, for more complex + default `jj` commands. + ### Fixed bugs * On Windows, symlinks in the repo are now supported when Developer Mode is enabled. diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index 895ad69d61..eca195a123 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -2171,6 +2171,16 @@ impl ValueParserFactory for RevisionArg { } } +fn get_string_or_array( + config: &config::Config, + key: &str, +) -> Result, config::ConfigError> { + config + .get(key) + .map(|string| vec![string]) + .or_else(|_| config.get::>(key)) +} + fn resolve_default_command( ui: &Ui, config: &config::Config, @@ -2194,7 +2204,8 @@ fn resolve_default_command( if let Some(matches) = matches { if matches.subcommand_name().is_none() { - if config.get_string("ui.default-command").is_err() { + let args = get_string_or_array(config, "ui.default-command"); + if args.is_err() { writeln!( ui.hint(), "Hint: Use `jj -h` for a list of available commands." @@ -2204,11 +2215,10 @@ fn resolve_default_command( "Run `jj config set --user ui.default-command log` to disable this message." )?; } - let default_command = config - .get_string("ui.default-command") - .unwrap_or_else(|_| "log".to_string()); + let default_command = args.unwrap_or_else(|_| vec!["log".to_string()]); + // Insert the default command directly after the path to the binary. - string_args.insert(1, default_command); + string_args.splice(1..1, default_command); } } Ok(string_args) diff --git a/cli/src/config-schema.json b/cli/src/config-schema.json index 5c768a0189..29a0b3e552 100644 --- a/cli/src/config-schema.json +++ b/cli/src/config-schema.json @@ -44,7 +44,18 @@ "default-command": { "type": "string", "description": "Default command to run when no explicit command is given", - "default": "log" + "default": "log", + "oneOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] }, "default-description": { "type": "string", diff --git a/cli/tests/test_global_opts.rs b/cli/tests/test_global_opts.rs index 3596460ed9..2cdea55749 100644 --- a/cli/tests/test_global_opts.rs +++ b/cli/tests/test_global_opts.rs @@ -101,6 +101,17 @@ fn test_no_subcommand() { │ (empty) (no description set) ~ "###); + + // Multiple default command strings work. + test_env.add_config(r#"ui.default-command=["commit", "-m", "foo"]"#); + test_env.jj_cmd_ok(&repo_path, &["new"]); + std::fs::write(repo_path.join("file.txt"), "file").unwrap(); + let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &[]); + assert_eq!(stdout, ""); + insta::assert_snapshot!(stderr, @r###" + Working copy now at: kxryzmor 70ac3df3 (empty) (no description set) + Parent commit : lylxulpl 9dbbb452 foo + "###); } #[test]