-
Notifications
You must be signed in to change notification settings - Fork 357
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
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,6 +125,72 @@ fn test_config_list_all() { | |
"###); | ||
} | ||
|
||
#[test] | ||
fn test_config_list_show_origin() { | ||
let mut test_env = TestEnvironment::default(); | ||
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]); | ||
let repo_path = test_env.env_root().join("repo"); | ||
|
||
// Create multiple user configs. | ||
test_env.add_config( | ||
r#" | ||
user-key-1 = "user-val-1" | ||
"#, | ||
); | ||
|
||
test_env.add_config( | ||
r#" | ||
user-key-2 = "user-val-2" | ||
"#, | ||
); | ||
|
||
// Env | ||
test_env.add_env_var("env-key", "env-value"); | ||
|
||
// Repo | ||
test_env.jj_cmd_ok( | ||
&repo_path, | ||
&["config", "set", "--repo", "repo-key", "repo-val"], | ||
); | ||
|
||
let stdout = test_env.jj_cmd_success( | ||
&repo_path, | ||
&[ | ||
"config", | ||
"list", | ||
"--config-toml", | ||
"cmd-key='cmd-val'", | ||
"--show-origin", | ||
], | ||
); | ||
|
||
// Paths starting with `$TEST_ENV` confirm that the relative path returned by | ||
// `Value.origin()` has been converted to an absolute path. | ||
insta::assert_snapshot!(stdout, @r###" | ||
usercfg $TEST_ENV/config/config0001.toml: template-aliases.format_time_range(time_range)="time_range.start() ++ \" - \" ++ time_range.end()" | ||
usercfg $TEST_ENV/config/config0002.toml: user-key-1="user-val-1" | ||
usercfg $TEST_ENV/config/config0003.toml: user-key-2="user-val-2" | ||
repocfg $TEST_ENV/repo/.jj/repo/config.toml: repo-key="repo-val" | ||
env: debug.commit-timestamp="2001-02-03T04:05:09+07:00" | ||
env: debug.operation-timestamp="2001-02-03T04:05:09+07:00" | ||
env: debug.randomness-seed="3" | ||
env: operation.hostname="host.example.com" | ||
env: operation.username="test-username" | ||
env: user.email="[email protected]" | ||
env: user.name="Test User" | ||
cmdline: cmd-key="cmd-val" | ||
"###); | ||
|
||
// Run again with defaults shown. Rather than assert the full output which | ||
// will change when any default config value is added or updated, check only | ||
// one value to validate the formatting is correct. | ||
let stdout = test_env.jj_cmd_success( | ||
&repo_path, | ||
&["config", "list", "--include-defaults", "--show-origin"], | ||
); | ||
assert!(stdout.contains(r#"default: colors.diff header="yellow""#)); | ||
} | ||
|
||
#[test] | ||
fn test_config_list_layer() { | ||
let mut test_env = TestEnvironment::default(); | ||
|
@@ -628,14 +694,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. | ||
"###); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
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 byconfig
were not. For example, an internalPAGER
key would not be set by environment variablePAGER
because the latter had been converted topager
.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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.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 definerevset-aliases.HEAD = "@-"
for example.There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!