mirror of
https://github.com/martinvonz/jj.git
synced 2025-05-05 15:32:49 +00:00
cli: add "$schema" line when creating new config file
It seems like a small usability improvement if users don't need to enter the "$schema" link manually when they create a new config file. This doesn't help existing users.
This commit is contained in:
parent
05fa4bc0a3
commit
103d05149d
@ -231,6 +231,7 @@ fn test_config_list_layer() {
|
|||||||
|
|
||||||
let output = work_dir.run_jj(["config", "list", "--user"]);
|
let output = work_dir.run_jj(["config", "list", "--user"]);
|
||||||
insta::assert_snapshot!(output, @r#"
|
insta::assert_snapshot!(output, @r#"
|
||||||
|
"$schema" = "https://jj-vcs.github.io/jj/latest/config-schema.json"
|
||||||
test-key = "test-val"
|
test-key = "test-val"
|
||||||
test-layered-key = "test-original-val"
|
test-layered-key = "test-original-val"
|
||||||
[EOF]
|
[EOF]
|
||||||
@ -255,6 +256,7 @@ fn test_config_list_layer() {
|
|||||||
|
|
||||||
let output = work_dir.run_jj(["config", "list", "--repo"]);
|
let output = work_dir.run_jj(["config", "list", "--repo"]);
|
||||||
insta::assert_snapshot!(output, @r#"
|
insta::assert_snapshot!(output, @r#"
|
||||||
|
"$schema" = "https://jj-vcs.github.io/jj/latest/config-schema.json"
|
||||||
test-layered-key = "test-layered-val"
|
test-layered-key = "test-layered-val"
|
||||||
[EOF]
|
[EOF]
|
||||||
"#);
|
"#);
|
||||||
@ -304,6 +306,7 @@ fn test_config_list_origin() {
|
|||||||
]);
|
]);
|
||||||
insta::assert_snapshot!(output, @r#"
|
insta::assert_snapshot!(output, @r#"
|
||||||
test-key = "test-val" # user $TEST_ENV/config/config.toml
|
test-key = "test-val" # user $TEST_ENV/config/config.toml
|
||||||
|
"$schema" = "https://jj-vcs.github.io/jj/latest/config-schema.json" # repo $TEST_ENV/repo/.jj/repo/config.toml
|
||||||
test-layered-key = "test-layered-val" # repo $TEST_ENV/repo/.jj/repo/config.toml
|
test-layered-key = "test-layered-val" # repo $TEST_ENV/repo/.jj/repo/config.toml
|
||||||
user.name = "Test User" # env
|
user.name = "Test User" # env
|
||||||
user.email = "test.user@example.com" # env
|
user.email = "test.user@example.com" # env
|
||||||
@ -597,6 +600,7 @@ fn test_config_set_for_user() {
|
|||||||
let user_config_toml = std::fs::read_to_string(&user_config_path)
|
let user_config_toml = std::fs::read_to_string(&user_config_path)
|
||||||
.unwrap_or_else(|_| panic!("Failed to read file {}", user_config_path.display()));
|
.unwrap_or_else(|_| panic!("Failed to read file {}", user_config_path.display()));
|
||||||
insta::assert_snapshot!(user_config_toml, @r#"
|
insta::assert_snapshot!(user_config_toml, @r#"
|
||||||
|
"$schema" = "https://jj-vcs.github.io/jj/latest/config-schema.json"
|
||||||
test-key = "test-val"
|
test-key = "test-val"
|
||||||
|
|
||||||
[test-table]
|
[test-table]
|
||||||
@ -663,6 +667,7 @@ fn test_config_set_for_repo() {
|
|||||||
// Ensure test-key successfully written to user config.
|
// Ensure test-key successfully written to user config.
|
||||||
let repo_config_toml = work_dir.read_file(".jj/repo/config.toml");
|
let repo_config_toml = work_dir.read_file(".jj/repo/config.toml");
|
||||||
insta::assert_snapshot!(repo_config_toml, @r#"
|
insta::assert_snapshot!(repo_config_toml, @r#"
|
||||||
|
"$schema" = "https://jj-vcs.github.io/jj/latest/config-schema.json"
|
||||||
test-key = "test-val"
|
test-key = "test-val"
|
||||||
|
|
||||||
[test-table]
|
[test-table]
|
||||||
@ -691,6 +696,8 @@ fn test_config_set_toml_types() {
|
|||||||
set_value("test-table.string", r#""foo""#);
|
set_value("test-table.string", r#""foo""#);
|
||||||
set_value("test-table.invalid", r"a + b");
|
set_value("test-table.invalid", r"a + b");
|
||||||
insta::assert_snapshot!(std::fs::read_to_string(&user_config_path).unwrap(), @r#"
|
insta::assert_snapshot!(std::fs::read_to_string(&user_config_path).unwrap(), @r#"
|
||||||
|
"$schema" = "https://jj-vcs.github.io/jj/latest/config-schema.json"
|
||||||
|
|
||||||
[test-table]
|
[test-table]
|
||||||
integer = 42
|
integer = 42
|
||||||
float = 3.14
|
float = 3.14
|
||||||
@ -784,7 +791,10 @@ fn test_config_unset_inline_table_key() {
|
|||||||
.run_jj(["config", "unset", "--user", "inline-table.foo"])
|
.run_jj(["config", "unset", "--user", "inline-table.foo"])
|
||||||
.success();
|
.success();
|
||||||
let user_config_toml = std::fs::read_to_string(&user_config_path).unwrap();
|
let user_config_toml = std::fs::read_to_string(&user_config_path).unwrap();
|
||||||
insta::assert_snapshot!(user_config_toml, @"inline-table = {}");
|
insta::assert_snapshot!(user_config_toml, @r#"
|
||||||
|
"$schema" = "https://jj-vcs.github.io/jj/latest/config-schema.json"
|
||||||
|
inline-table = {}
|
||||||
|
"#);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -856,7 +866,11 @@ fn test_config_unset_for_user() {
|
|||||||
.success();
|
.success();
|
||||||
|
|
||||||
let user_config_toml = std::fs::read_to_string(&user_config_path).unwrap();
|
let user_config_toml = std::fs::read_to_string(&user_config_path).unwrap();
|
||||||
insta::assert_snapshot!(user_config_toml, @"[table]");
|
insta::assert_snapshot!(user_config_toml, @r#"
|
||||||
|
"$schema" = "https://jj-vcs.github.io/jj/latest/config-schema.json"
|
||||||
|
|
||||||
|
[table]
|
||||||
|
"#);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -873,7 +887,7 @@ fn test_config_unset_for_repo() {
|
|||||||
.success();
|
.success();
|
||||||
|
|
||||||
let repo_config_toml = work_dir.read_file(".jj/repo/config.toml");
|
let repo_config_toml = work_dir.read_file(".jj/repo/config.toml");
|
||||||
insta::assert_snapshot!(repo_config_toml, @"");
|
insta::assert_snapshot!(repo_config_toml, @r#""$schema" = "https://jj-vcs.github.io/jj/latest/config-schema.json""#);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -559,11 +559,19 @@ impl ConfigFile {
|
|||||||
Err(ConfigLoadError::Read(PathError { path, error }))
|
Err(ConfigLoadError::Read(PathError { path, error }))
|
||||||
if error.kind() == io::ErrorKind::NotFound =>
|
if error.kind() == io::ErrorKind::NotFound =>
|
||||||
{
|
{
|
||||||
Arc::new(ConfigLayer {
|
let mut data = DocumentMut::new();
|
||||||
|
data.insert(
|
||||||
|
"$schema",
|
||||||
|
toml_edit::Item::Value(
|
||||||
|
"https://jj-vcs.github.io/jj/latest/config-schema.json".into(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
let layer = ConfigLayer {
|
||||||
source,
|
source,
|
||||||
path: Some(path),
|
path: Some(path),
|
||||||
data: DocumentMut::new(),
|
data,
|
||||||
})
|
};
|
||||||
|
Arc::new(layer)
|
||||||
}
|
}
|
||||||
Err(err) => return Err(err),
|
Err(err) => return Err(err),
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user