-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cli: Add
--show-sources
option to config list
Add a new `--show-sources` option to `jj config list` to display the source type and file path (when present) of config values. In cases where the user config path is a directory, the individual file containing a given value will be displayed. The method that captures config file paths, `config::FileSourceFile::resolve()`, converts them to relative paths. This is a good fit for repository config files, as the working directory is likely to be have a short path to `.jj/repo`. However, the user's home directory may be some distance from the current working directory, making it difficult to recognize where the config file is located. For example: ../../../../.config/jj/config.toml vs /home/user/.config/jj/config.toml We therefore attempt to canonicalize the path for user config files. Should this fail, we use the path as-is.
- Loading branch information
Will Chandler
committed
Feb 11, 2024
1 parent
fe842e0
commit 2c29cdc
Showing
5 changed files
with
119 additions
and
2 deletions.
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
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_sources() { | ||
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-sources", | ||
], | ||
); | ||
|
||
// 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:.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" | ||
command line: 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-sources"], | ||
); | ||
assert!(stdout.contains(r#"default: colors.diff header="yellow""#)); | ||
} | ||
|
||
#[test] | ||
fn test_config_list_layer() { | ||
let mut test_env = TestEnvironment::default(); | ||
|