mirror of
https://github.com/martinvonz/jj.git
synced 2025-05-05 07:22:50 +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"]);
|
||||
insta::assert_snapshot!(output, @r#"
|
||||
"$schema" = "https://jj-vcs.github.io/jj/latest/config-schema.json"
|
||||
test-key = "test-val"
|
||||
test-layered-key = "test-original-val"
|
||||
[EOF]
|
||||
@ -255,6 +256,7 @@ fn test_config_list_layer() {
|
||||
|
||||
let output = work_dir.run_jj(["config", "list", "--repo"]);
|
||||
insta::assert_snapshot!(output, @r#"
|
||||
"$schema" = "https://jj-vcs.github.io/jj/latest/config-schema.json"
|
||||
test-layered-key = "test-layered-val"
|
||||
[EOF]
|
||||
"#);
|
||||
@ -304,6 +306,7 @@ fn test_config_list_origin() {
|
||||
]);
|
||||
insta::assert_snapshot!(output, @r#"
|
||||
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
|
||||
user.name = "Test User" # 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)
|
||||
.unwrap_or_else(|_| panic!("Failed to read file {}", user_config_path.display()));
|
||||
insta::assert_snapshot!(user_config_toml, @r#"
|
||||
"$schema" = "https://jj-vcs.github.io/jj/latest/config-schema.json"
|
||||
test-key = "test-val"
|
||||
|
||||
[test-table]
|
||||
@ -663,6 +667,7 @@ fn test_config_set_for_repo() {
|
||||
// Ensure test-key successfully written to user config.
|
||||
let repo_config_toml = work_dir.read_file(".jj/repo/config.toml");
|
||||
insta::assert_snapshot!(repo_config_toml, @r#"
|
||||
"$schema" = "https://jj-vcs.github.io/jj/latest/config-schema.json"
|
||||
test-key = "test-val"
|
||||
|
||||
[test-table]
|
||||
@ -691,6 +696,8 @@ fn test_config_set_toml_types() {
|
||||
set_value("test-table.string", r#""foo""#);
|
||||
set_value("test-table.invalid", r"a + b");
|
||||
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]
|
||||
integer = 42
|
||||
float = 3.14
|
||||
@ -784,7 +791,10 @@ fn test_config_unset_inline_table_key() {
|
||||
.run_jj(["config", "unset", "--user", "inline-table.foo"])
|
||||
.success();
|
||||
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]
|
||||
@ -856,7 +866,11 @@ fn test_config_unset_for_user() {
|
||||
.success();
|
||||
|
||||
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]
|
||||
@ -873,7 +887,7 @@ fn test_config_unset_for_repo() {
|
||||
.success();
|
||||
|
||||
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]
|
||||
|
@ -559,11 +559,19 @@ impl ConfigFile {
|
||||
Err(ConfigLoadError::Read(PathError { path, error }))
|
||||
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,
|
||||
path: Some(path),
|
||||
data: DocumentMut::new(),
|
||||
})
|
||||
data,
|
||||
};
|
||||
Arc::new(layer)
|
||||
}
|
||||
Err(err) => return Err(err),
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user