mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-12 23:23:20 +00:00
config: don't leave empty tables visible by set_value()
It's unlikely that user would want to define all intermediate tables by "jj config set foo.bar.baz ..".
This commit is contained in:
parent
4af39e2038
commit
10783f9e70
1 changed files with 7 additions and 3 deletions
|
@ -476,12 +476,18 @@ fn ensure_parent_table<'a, 'b>(
|
|||
let mut keys = name.components();
|
||||
let leaf_key = keys.next_back().ok_or(&name.0[..])?;
|
||||
let parent_table = keys.enumerate().try_fold(root_table, |table, (i, key)| {
|
||||
let sub_item = table.entry(key).or_insert_with(toml_edit::table);
|
||||
let sub_item = table.entry(key).or_insert_with(new_implicit_table);
|
||||
sub_item.as_table_mut().ok_or(&name.0[..=i])
|
||||
})?;
|
||||
Ok((parent_table, leaf_key))
|
||||
}
|
||||
|
||||
fn new_implicit_table() -> ConfigItem {
|
||||
let mut table = ConfigTable::new();
|
||||
table.set_implicit(true);
|
||||
ConfigItem::Table(table)
|
||||
}
|
||||
|
||||
/// Wrapper for file-based [`ConfigLayer`], providing convenient methods for
|
||||
/// modification.
|
||||
#[derive(Debug)]
|
||||
|
@ -952,8 +958,6 @@ mod tests {
|
|||
// exist
|
||||
assert_matches!(layer.delete_value("bar.baz.blah.blah"), Ok(None));
|
||||
insta::assert_snapshot!(layer.data, @r#"
|
||||
[bar]
|
||||
|
||||
[bar.baz]
|
||||
blah = "2"
|
||||
"#);
|
||||
|
|
Loading…
Reference in a new issue