Skip to content

Commit

Permalink
config: don't leave empty tables visible by set_value()
Browse files Browse the repository at this point in the history
It's unlikely that user would want to define all intermediate tables by
"jj config set foo.bar.baz ..".
  • Loading branch information
yuja committed Dec 29, 2024
1 parent 4af39e2 commit 10783f9
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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"
"#);
Expand Down

0 comments on commit 10783f9

Please sign in to comment.