Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: Add --show-origin option to config list #3023

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ chrono = { version = "0.4.34", default-features = false, features = [
"std",
"clock",
] }
config = { version = "0.13.4", default-features = false, features = ["toml"] }
config = { version = "0.14.0", default-features = false, features = ["toml"] }
criterion = "0.5.1"
crossterm = { version = "0.27", default-features = false }
digest = "0.10.7"
Expand Down
4 changes: 2 additions & 2 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,8 @@ mod tests {
command_args,
CommandNameAndArgs::Structured {
env: hashmap! {
"KEY1".to_string() => "value1".to_string(),
"KEY2".to_string() => "value2".to_string(),
"key1".to_string() => "value1".to_string(),
"key2".to_string() => "value2".to_string(),
Copy link
Contributor

@yuja yuja Feb 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

environment config variables are no longer case-sensitive

Oops, it probably means the structured command config no longer works. Environment variables are case sensitive on Unix, and we do use the TOML table syntax to override them.
[EDIT] Alias definitions, merge tools, etc. will also get broken.

Maybe it's time to roll our own config module? I think it will help implement #616 and/or handle colors/revset-aliases overrides better.

Sorry for the late reply. I didn't notice this yesterday.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think my summary of what changed in config v0.14.0 is not quite right. Prior to v0.14.0 environment variable keys were already being downcased, see rust-cli/config-rs#340, but the internal keys tracked by config were not. For example, an internal PAGER key would not be set by environment variable PAGER because the latter had been converted to pager.

The change in rust-cli/config-rs#354 was to downcase the internal keys as well. Looking at the config schema I don't see any mixed case settings, do you have an example of what you would expect to break so I can be sure I understand?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prior to v0.14.0 environment variable keys were already being downcased

I think you're talking about the config loaded from environment variables, but this CommandNameAndArgs stuff is data configured in a config file, and passed to the external process. So the case matters.

do you have an example of what you would expect to break

In addition to this, [aliases], [revset-aliases], [template-aliases], [merge-tools.<NAME>] would break if keys are downcased. They are free-form dictionary, and users may define revset-aliases.HEAD = "@-" for example.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wfchandler: To clarify, I think Yuya is talking about https://github.com/martinvonz/jj/blob/26528091e646a79a3724997f06c4af69eaf70297/cli/src/config/misc.toml#L9 (the user can have their own similar config). (Correct me if I'm wrong, @yuja.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps, this is the upstream issue. It doesn't describe the exact problem we have, but the root cause would be the same.
rust-cli/config-rs#531

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation, I see what you mean. I'll go ahead and close out this PR given the problem with config v0.14.0.

Thank you @yuja @martinvonz and @jonathantanmy for the thorough review, much better to have caught this issue now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope the problem will be addressed at config-rs, and this PR can be revisited later. Thanks anyways.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks for trying, and sorry about the trouble. And thanks to Yuya for noticing the problem!

},
command: NonEmptyCommandArgsVec(["emacs", "-nw",].map(|s| s.to_owned()).to_vec())
}
Expand Down
10 changes: 6 additions & 4 deletions cli/tests/test_config_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,14 +628,16 @@ fn test_config_get() {
"###);

let stdout = test_env.jj_cmd_failure(test_env.env_root(), &["config", "get", "table.list"]);
insta::assert_snapshot!(stdout, @r###"
Config error: invalid type: sequence, expected a value convertible to a string
insta::with_settings!({filters => vec![(r"config\\config0002.toml", "config/config0002.toml")]}, {
insta::assert_snapshot!(stdout, @r###"
Config error: invalid type: sequence, expected a value convertible to a string for key `table.list` in config/config0002.toml
For help, see https://github.com/martinvonz/jj/blob/main/docs/config.md.
"###);
"###)
});

let stdout = test_env.jj_cmd_failure(test_env.env_root(), &["config", "get", "table"]);
insta::assert_snapshot!(stdout, @r###"
Config error: invalid type: map, expected a value convertible to a string
Config error: invalid type: map, expected a value convertible to a string for key `table`
For help, see https://github.com/martinvonz/jj/blob/main/docs/config.md.
"###);

Expand Down
8 changes: 7 additions & 1 deletion cli/tests/test_global_opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,13 @@ fn test_invalid_config() {
test_env.add_config("[section]key = value-missing-quotes");
let stderr = test_env.jj_cmd_failure(test_env.env_root(), &["init", "repo"]);
insta::assert_snapshot!(stderr.replace('\\', "/"), @r###"
Config error: expected newline, found an identifier at line 1 column 10 in config/config0002.toml
Config error: TOML parse error at line 1, column 10
|
1 | [section]key = value-missing-quotes
| ^
invalid table header
expected newline, `#`
in config/config0002.toml
For help, see https://github.com/martinvonz/jj/blob/main/docs/config.md.
"###);
}
Expand Down