forked from mirrors/jj
config: rename [alias] to [aliases], still supporting old name
The name of the [alias] section is inconsistent with other table-valued sections ([revset-aliases], [colors], [merge-tools]), so let's rename it. For comparison, `Cargo.toml` also uses plural names (e.g. `[dependencies]`).
This commit is contained in:
parent
8af38f0d75
commit
5ec5f4bb5f
5 changed files with 49 additions and 11 deletions
|
@ -83,6 +83,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
* `jj workspace root` prints the root path of the current workspace.
|
||||
|
||||
* The `[alias]` config section was renamed to `[aliases]`. The old name is
|
||||
still accepted for backwards compatibility for some time.
|
||||
|
||||
### Fixed bugs
|
||||
|
||||
* When sharing the working copy with a Git repo, we used to forget to export
|
||||
|
|
|
@ -1718,7 +1718,18 @@ fn resolve_aliases(
|
|||
app: &Command,
|
||||
string_args: &[String],
|
||||
) -> Result<Vec<String>, CommandError> {
|
||||
let mut aliases_map = config.get_table("alias")?;
|
||||
let mut aliases_map = config.get_table("aliases")?;
|
||||
if let Ok(alias_map) = config.get_table("alias") {
|
||||
for (alias, definition) in alias_map {
|
||||
if aliases_map.insert(alias.clone(), definition).is_some() {
|
||||
return Err(user_error_with_hint(
|
||||
format!(r#"Alias "{alias}" is defined in both [aliases] and [alias]"#),
|
||||
"[aliases] is the preferred section for aliases. Please remove the alias from \
|
||||
[alias].",
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut resolved_aliases = HashSet::new();
|
||||
let mut string_args = string_args.to_vec();
|
||||
let mut real_commands = HashSet::new();
|
||||
|
|
|
@ -140,7 +140,7 @@
|
|||
"type": "string"
|
||||
}
|
||||
},
|
||||
"alias": {
|
||||
"aliases": {
|
||||
"type": "object",
|
||||
"description": "Custom subcommand aliases to be supported by the jj command",
|
||||
"additionalProperties": {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[alias]
|
||||
[aliases]
|
||||
# Placeholder: added by user
|
||||
|
||||
[git]
|
||||
|
|
|
@ -24,6 +24,22 @@ fn test_alias_basic() {
|
|||
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
||||
let repo_path = test_env.env_root().join("repo");
|
||||
|
||||
test_env.add_config(r#"aliases.b = ["log", "-r", "@", "-T", "branches"]"#);
|
||||
test_env.jj_cmd_success(&repo_path, &["branch", "create", "my-branch"]);
|
||||
let stdout = test_env.jj_cmd_success(&repo_path, &["b"]);
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
@ my-branch
|
||||
~
|
||||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_alias_legacy_section() {
|
||||
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");
|
||||
|
||||
// Can define aliases in [alias] section
|
||||
test_env.add_config(r#"alias.b = ["log", "-r", "@", "-T", "branches"]"#);
|
||||
test_env.jj_cmd_success(&repo_path, &["branch", "create", "my-branch"]);
|
||||
let stdout = test_env.jj_cmd_success(&repo_path, &["b"]);
|
||||
|
@ -31,6 +47,14 @@ fn test_alias_basic() {
|
|||
@ my-branch
|
||||
~
|
||||
"###);
|
||||
|
||||
// The same alias (name) in both [alias] and [aliases] sections is an error
|
||||
test_env.add_config(r#"aliases.b = ["branch", "list"]"#);
|
||||
let stderr = test_env.jj_cmd_failure(&repo_path, &["b"]);
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Error: Alias "b" is defined in both [aliases] and [alias]
|
||||
Hint: [aliases] is the preferred section for aliases. Please remove the alias from [alias].
|
||||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -55,7 +79,7 @@ fn test_alias_calls_unknown_command() {
|
|||
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
||||
let repo_path = test_env.env_root().join("repo");
|
||||
|
||||
test_env.add_config(r#"alias.foo = ["nonexistent"]"#);
|
||||
test_env.add_config(r#"aliases.foo = ["nonexistent"]"#);
|
||||
let stderr = test_env.jj_cmd_cli_error(&repo_path, &["foo"]);
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
error: The subcommand 'nonexistent' wasn't recognized
|
||||
|
@ -72,7 +96,7 @@ fn test_alias_calls_command_with_invalid_option() {
|
|||
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
||||
let repo_path = test_env.env_root().join("repo");
|
||||
|
||||
test_env.add_config(r#"alias.foo = ["log", "--nonexistent"]"#);
|
||||
test_env.add_config(r#"aliases.foo = ["log", "--nonexistent"]"#);
|
||||
let stderr = test_env.jj_cmd_cli_error(&repo_path, &["foo"]);
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
error: Found argument '--nonexistent' which wasn't expected, or isn't valid in this context
|
||||
|
@ -90,7 +114,7 @@ fn test_alias_calls_help() {
|
|||
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");
|
||||
test_env.add_config(r#"alias.h = ["--help"]"#);
|
||||
test_env.add_config(r#"aliases.h = ["--help"]"#);
|
||||
let stdout = test_env.jj_cmd_success(&repo_path, &["h"]);
|
||||
insta::assert_snapshot!(stdout.lines().take(5).join("\n"), @r###"
|
||||
Jujutsu (An experimental VCS)
|
||||
|
@ -107,7 +131,7 @@ fn test_alias_cannot_override_builtin() {
|
|||
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
||||
let repo_path = test_env.env_root().join("repo");
|
||||
|
||||
test_env.add_config(r#"alias.log = ["rebase"]"#);
|
||||
test_env.add_config(r#"aliases.log = ["rebase"]"#);
|
||||
// Alias should be ignored
|
||||
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "root"]);
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
|
@ -123,7 +147,7 @@ fn test_alias_recursive() {
|
|||
let repo_path = test_env.env_root().join("repo");
|
||||
|
||||
test_env.add_config(
|
||||
r#"[alias]
|
||||
r#"[aliases]
|
||||
foo = ["foo"]
|
||||
bar = ["baz"]
|
||||
baz = ["bar"]
|
||||
|
@ -146,7 +170,7 @@ fn test_alias_global_args_before_and_after() {
|
|||
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");
|
||||
test_env.add_config(r#"alias.l = ["log", "-T", "commit_id", "-r", "all()"]"#);
|
||||
test_env.add_config(r#"aliases.l = ["log", "-T", "commit_id", "-r", "all()"]"#);
|
||||
// Test the setup
|
||||
let stdout = test_env.jj_cmd_success(&repo_path, &["l"]);
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
|
@ -182,7 +206,7 @@ fn test_alias_global_args_in_definition() {
|
|||
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
||||
let repo_path = test_env.env_root().join("repo");
|
||||
test_env.add_config(
|
||||
r#"alias.l = ["log", "-T", "commit_id", "--at-op", "@-", "-r", "all()", "--color=always"]"#,
|
||||
r#"aliases.l = ["log", "-T", "commit_id", "--at-op", "@-", "-r", "all()", "--color=always"]"#,
|
||||
);
|
||||
|
||||
// The global argument in the alias is respected
|
||||
|
@ -197,7 +221,7 @@ fn test_alias_invalid_definition() {
|
|||
let test_env = TestEnvironment::default();
|
||||
|
||||
test_env.add_config(
|
||||
r#"[alias]
|
||||
r#"[aliases]
|
||||
non-list = 5
|
||||
non-string-list = [[]]
|
||||
"#,
|
||||
|
|
Loading…
Reference in a new issue