2022-12-13 06:22:08 +00:00
|
|
|
|
// Copyright 2022 The Jujutsu Authors
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
2024-02-01 04:53:23 +00:00
|
|
|
|
use insta::assert_snapshot;
|
2022-12-13 06:22:08 +00:00
|
|
|
|
use itertools::Itertools;
|
|
|
|
|
use regex::Regex;
|
|
|
|
|
|
|
|
|
|
use crate::common::TestEnvironment;
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_config_list_single() {
|
|
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
|
test_env.add_config(
|
2023-08-15 03:18:52 +00:00
|
|
|
|
r#"
|
2022-12-13 06:22:08 +00:00
|
|
|
|
[test-table]
|
|
|
|
|
somekey = "some value"
|
2023-08-15 03:18:52 +00:00
|
|
|
|
"#,
|
2022-12-13 06:22:08 +00:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let stdout = test_env.jj_cmd_success(
|
|
|
|
|
test_env.env_root(),
|
|
|
|
|
&["config", "list", "test-table.somekey"],
|
|
|
|
|
);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
test-table.somekey="some value"
|
|
|
|
|
"###);
|
2024-03-03 11:45:36 +00:00
|
|
|
|
|
|
|
|
|
let stdout = test_env.jj_cmd_success(
|
|
|
|
|
test_env.env_root(),
|
|
|
|
|
&["config", "list", r#"-Tname ++ "\n""#, "test-table.somekey"],
|
|
|
|
|
);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
test-table.somekey
|
|
|
|
|
"###);
|
2022-12-13 06:22:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-12 06:24:39 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_config_list_nonexistent() {
|
|
|
|
|
let test_env = TestEnvironment::default();
|
2023-07-03 10:04:31 +00:00
|
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(
|
|
|
|
|
test_env.env_root(),
|
|
|
|
|
&["config", "list", "nonexistent-test-key"],
|
|
|
|
|
);
|
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-03-24 06:47:47 +00:00
|
|
|
|
Warning: No matching config key for nonexistent-test-key
|
2023-01-12 06:24:39 +00:00
|
|
|
|
"###);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-13 06:22:08 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_config_list_table() {
|
|
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
|
test_env.add_config(
|
2023-08-15 03:18:52 +00:00
|
|
|
|
r#"
|
2022-12-13 06:22:08 +00:00
|
|
|
|
[test-table]
|
|
|
|
|
x = true
|
|
|
|
|
y.foo = "abc"
|
|
|
|
|
y.bar = 123
|
2023-08-15 03:18:52 +00:00
|
|
|
|
"#,
|
2022-12-13 06:22:08 +00:00
|
|
|
|
);
|
|
|
|
|
let stdout = test_env.jj_cmd_success(test_env.env_root(), &["config", "list", "test-table"]);
|
|
|
|
|
insta::assert_snapshot!(
|
|
|
|
|
stdout,
|
|
|
|
|
@r###"
|
|
|
|
|
test-table.x=true
|
|
|
|
|
test-table.y.bar=123
|
|
|
|
|
test-table.y.foo="abc"
|
|
|
|
|
"###);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_config_list_array() {
|
|
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
|
test_env.add_config(
|
2023-08-15 03:18:52 +00:00
|
|
|
|
r#"
|
2022-12-13 06:22:08 +00:00
|
|
|
|
test-array = [1, "b", 3.4]
|
2023-08-15 03:18:52 +00:00
|
|
|
|
"#,
|
2022-12-13 06:22:08 +00:00
|
|
|
|
);
|
|
|
|
|
let stdout = test_env.jj_cmd_success(test_env.env_root(), &["config", "list", "test-array"]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
test-array=[1, "b", 3.4]
|
|
|
|
|
"###);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_config_list_inline_table() {
|
|
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
|
test_env.add_config(
|
2023-08-15 03:18:52 +00:00
|
|
|
|
r#"
|
2022-12-13 06:22:08 +00:00
|
|
|
|
[[test-table]]
|
|
|
|
|
x = 1
|
|
|
|
|
[[test-table]]
|
|
|
|
|
y = ["z"]
|
2023-08-15 03:18:52 +00:00
|
|
|
|
"#,
|
2022-12-13 06:22:08 +00:00
|
|
|
|
);
|
|
|
|
|
let stdout = test_env.jj_cmd_success(test_env.env_root(), &["config", "list", "test-table"]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
test-table=[{x=1}, {y=["z"]}]
|
|
|
|
|
"###);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_config_list_all() {
|
|
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
|
test_env.add_config(
|
2023-08-15 03:18:52 +00:00
|
|
|
|
r#"
|
2022-12-13 06:22:08 +00:00
|
|
|
|
test-val = [1, 2, 3]
|
|
|
|
|
[test-table]
|
|
|
|
|
x = true
|
|
|
|
|
y.foo = "abc"
|
|
|
|
|
y.bar = 123
|
2023-08-15 03:18:52 +00:00
|
|
|
|
"#,
|
2022-12-13 06:22:08 +00:00
|
|
|
|
);
|
2024-03-03 11:45:36 +00:00
|
|
|
|
|
2022-12-13 06:22:08 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(test_env.env_root(), &["config", "list"]);
|
|
|
|
|
insta::assert_snapshot!(
|
|
|
|
|
find_stdout_lines(r"(test-val|test-table\b[^=]*)", &stdout),
|
|
|
|
|
@r###"
|
|
|
|
|
test-table.x=true
|
|
|
|
|
test-table.y.bar=123
|
|
|
|
|
test-table.y.foo="abc"
|
|
|
|
|
test-val=[1, 2, 3]
|
|
|
|
|
"###);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-14 01:38:55 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_config_list_layer() {
|
|
|
|
|
let mut test_env = TestEnvironment::default();
|
|
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
|
|
|
|
|
let user_config_path = test_env.config_path().join("config.toml");
|
|
|
|
|
test_env.set_config_path(user_config_path.to_owned());
|
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
|
|
|
|
// User
|
|
|
|
|
test_env.jj_cmd_ok(
|
|
|
|
|
&repo_path,
|
|
|
|
|
&["config", "set", "--user", "test-key", "test-val"],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
test_env.jj_cmd_ok(
|
|
|
|
|
&repo_path,
|
|
|
|
|
&[
|
|
|
|
|
"config",
|
|
|
|
|
"set",
|
|
|
|
|
"--user",
|
|
|
|
|
"test-layered-key",
|
|
|
|
|
"test-original-val",
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["config", "list", "--user"]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
test-key="test-val"
|
|
|
|
|
test-layered-key="test-original-val"
|
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
// Repo
|
|
|
|
|
test_env.jj_cmd_ok(
|
|
|
|
|
&repo_path,
|
|
|
|
|
&[
|
|
|
|
|
"config",
|
|
|
|
|
"set",
|
|
|
|
|
"--repo",
|
|
|
|
|
"test-layered-key",
|
|
|
|
|
"test-layered-val",
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["config", "list", "--user"]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
test-key="test-val"
|
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["config", "list", "--repo"]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
test-layered-key="test-layered-val"
|
|
|
|
|
"###);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-05 08:28:47 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_config_layer_override_default() {
|
|
|
|
|
let test_env = TestEnvironment::default();
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
|
2023-01-05 08:28:47 +00:00
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
let config_key = "merge-tools.vimdiff.program";
|
|
|
|
|
|
|
|
|
|
// Default
|
2023-01-12 06:24:39 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(
|
|
|
|
|
&repo_path,
|
|
|
|
|
&["config", "list", config_key, "--include-defaults"],
|
|
|
|
|
);
|
2023-01-05 08:28:47 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
merge-tools.vimdiff.program="vim"
|
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
// User
|
2023-01-26 19:26:18 +00:00
|
|
|
|
test_env.add_config(&format!("{config_key} = {value:?}\n", value = "user"));
|
2023-01-05 08:28:47 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["config", "list", config_key]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
merge-tools.vimdiff.program="user"
|
|
|
|
|
"###);
|
|
|
|
|
|
2023-01-02 05:18:38 +00:00
|
|
|
|
// Repo
|
|
|
|
|
std::fs::write(
|
|
|
|
|
repo_path.join(".jj/repo/config.toml"),
|
|
|
|
|
format!("{config_key} = {value:?}\n", value = "repo"),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["config", "list", config_key]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
merge-tools.vimdiff.program="repo"
|
|
|
|
|
"###);
|
|
|
|
|
|
2023-01-05 08:28:47 +00:00
|
|
|
|
// Command argument
|
|
|
|
|
let stdout = test_env.jj_cmd_success(
|
|
|
|
|
&repo_path,
|
|
|
|
|
&[
|
|
|
|
|
"config",
|
|
|
|
|
"list",
|
|
|
|
|
config_key,
|
|
|
|
|
"--config-toml",
|
|
|
|
|
&format!("{config_key}={value:?}", value = "command-arg"),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
merge-tools.vimdiff.program="command-arg"
|
|
|
|
|
"###);
|
2024-01-15 19:24:27 +00:00
|
|
|
|
|
|
|
|
|
// Allow printing overridden values
|
|
|
|
|
let stdout = test_env.jj_cmd_success(
|
|
|
|
|
&repo_path,
|
|
|
|
|
&[
|
|
|
|
|
"config",
|
|
|
|
|
"list",
|
|
|
|
|
config_key,
|
|
|
|
|
"--include-overridden",
|
|
|
|
|
"--config-toml",
|
|
|
|
|
&format!("{config_key}={value:?}", value = "command-arg"),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
# merge-tools.vimdiff.program="user"
|
|
|
|
|
# merge-tools.vimdiff.program="repo"
|
|
|
|
|
merge-tools.vimdiff.program="command-arg"
|
|
|
|
|
"###);
|
2024-03-04 09:35:14 +00:00
|
|
|
|
|
|
|
|
|
let stdout = test_env.jj_cmd_success(
|
|
|
|
|
&repo_path,
|
|
|
|
|
&[
|
|
|
|
|
"config",
|
|
|
|
|
"list",
|
|
|
|
|
"--color=always",
|
|
|
|
|
config_key,
|
|
|
|
|
"--include-overridden",
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
[38;5;8m# merge-tools.vimdiff.program="user"[39m
|
|
|
|
|
[38;5;2mmerge-tools.vimdiff.program[39m=[38;5;3m"repo"[39m
|
|
|
|
|
"###);
|
2023-01-05 08:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_config_layer_override_env() {
|
|
|
|
|
let mut test_env = TestEnvironment::default();
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
|
2023-01-05 08:28:47 +00:00
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
let config_key = "ui.editor";
|
|
|
|
|
|
|
|
|
|
// Environment base
|
|
|
|
|
test_env.add_env_var("EDITOR", "env-base");
|
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["config", "list", config_key]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
ui.editor="env-base"
|
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
// User
|
2023-01-26 19:26:18 +00:00
|
|
|
|
test_env.add_config(&format!("{config_key} = {value:?}\n", value = "user"));
|
2023-01-05 08:28:47 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["config", "list", config_key]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
ui.editor="user"
|
|
|
|
|
"###);
|
|
|
|
|
|
2023-01-02 05:18:38 +00:00
|
|
|
|
// Repo
|
|
|
|
|
std::fs::write(
|
|
|
|
|
repo_path.join(".jj/repo/config.toml"),
|
|
|
|
|
format!("{config_key} = {value:?}\n", value = "repo"),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["config", "list", config_key]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
ui.editor="repo"
|
|
|
|
|
"###);
|
|
|
|
|
|
2023-01-05 08:28:47 +00:00
|
|
|
|
// Environment override
|
|
|
|
|
test_env.add_env_var("JJ_EDITOR", "env-override");
|
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["config", "list", config_key]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
ui.editor="env-override"
|
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
// Command argument
|
|
|
|
|
let stdout = test_env.jj_cmd_success(
|
|
|
|
|
&repo_path,
|
|
|
|
|
&[
|
|
|
|
|
"config",
|
|
|
|
|
"list",
|
|
|
|
|
config_key,
|
|
|
|
|
"--config-toml",
|
|
|
|
|
&format!("{config_key}={value:?}", value = "command-arg"),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
ui.editor="command-arg"
|
|
|
|
|
"###);
|
2024-01-15 19:24:27 +00:00
|
|
|
|
|
|
|
|
|
// Allow printing overridden values
|
|
|
|
|
let stdout = test_env.jj_cmd_success(
|
|
|
|
|
&repo_path,
|
|
|
|
|
&[
|
|
|
|
|
"config",
|
|
|
|
|
"list",
|
|
|
|
|
config_key,
|
|
|
|
|
"--include-overridden",
|
|
|
|
|
"--config-toml",
|
|
|
|
|
&format!("{config_key}={value:?}", value = "command-arg"),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
# ui.editor="env-base"
|
|
|
|
|
# ui.editor="user"
|
|
|
|
|
# ui.editor="repo"
|
|
|
|
|
# ui.editor="env-override"
|
|
|
|
|
ui.editor="command-arg"
|
|
|
|
|
"###);
|
2023-01-05 08:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-02 05:18:38 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_config_layer_workspace() {
|
|
|
|
|
let test_env = TestEnvironment::default();
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["init", "--git", "main"]);
|
2023-01-02 05:18:38 +00:00
|
|
|
|
let main_path = test_env.env_root().join("main");
|
|
|
|
|
let secondary_path = test_env.env_root().join("secondary");
|
|
|
|
|
let config_key = "ui.editor";
|
|
|
|
|
|
|
|
|
|
std::fs::write(main_path.join("file"), "contents").unwrap();
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(&main_path, &["new"]);
|
|
|
|
|
test_env.jj_cmd_ok(
|
2023-01-02 05:18:38 +00:00
|
|
|
|
&main_path,
|
|
|
|
|
&["workspace", "add", "--name", "second", "../secondary"],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Repo
|
|
|
|
|
std::fs::write(
|
|
|
|
|
main_path.join(".jj/repo/config.toml"),
|
|
|
|
|
format!("{config_key} = {value:?}\n", value = "main-repo"),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
let stdout = test_env.jj_cmd_success(&main_path, &["config", "list", config_key]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
ui.editor="main-repo"
|
|
|
|
|
"###);
|
|
|
|
|
let stdout = test_env.jj_cmd_success(&secondary_path, &["config", "list", config_key]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
ui.editor="main-repo"
|
|
|
|
|
"###);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-15 04:23:44 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_config_set_missing_opts() {
|
|
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
|
let stderr = test_env.jj_cmd_cli_error(test_env.env_root(), &["config", "set"]);
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2023-03-17 23:14:20 +00:00
|
|
|
|
error: the following required arguments were not provided:
|
2023-01-15 04:23:44 +00:00
|
|
|
|
<--user|--repo>
|
|
|
|
|
<NAME>
|
|
|
|
|
<VALUE>
|
|
|
|
|
|
|
|
|
|
Usage: jj config set <--user|--repo> <NAME> <VALUE>
|
|
|
|
|
|
2023-03-17 23:14:20 +00:00
|
|
|
|
For more information, try '--help'.
|
2023-01-15 04:23:44 +00:00
|
|
|
|
"###);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_config_set_for_user() {
|
|
|
|
|
let mut test_env = TestEnvironment::default();
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
|
2023-01-15 04:23:44 +00:00
|
|
|
|
// Point to a config file since `config set` can't handle directories.
|
|
|
|
|
let user_config_path = test_env.config_path().join("config.toml");
|
|
|
|
|
test_env.set_config_path(user_config_path.to_owned());
|
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(
|
2023-01-15 04:23:44 +00:00
|
|
|
|
&repo_path,
|
|
|
|
|
&["config", "set", "--user", "test-key", "test-val"],
|
|
|
|
|
);
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(
|
2023-01-15 04:23:44 +00:00
|
|
|
|
&repo_path,
|
|
|
|
|
&["config", "set", "--user", "test-table.foo", "true"],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Ensure test-key successfully written to user config.
|
|
|
|
|
let user_config_toml = std::fs::read_to_string(&user_config_path)
|
|
|
|
|
.unwrap_or_else(|_| panic!("Failed to read file {}", user_config_path.display()));
|
|
|
|
|
insta::assert_snapshot!(user_config_toml, @r###"
|
|
|
|
|
test-key = "test-val"
|
|
|
|
|
|
|
|
|
|
[test-table]
|
|
|
|
|
foo = true
|
|
|
|
|
"###);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_config_set_for_repo() {
|
|
|
|
|
let test_env = TestEnvironment::default();
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
|
2023-01-15 04:23:44 +00:00
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(
|
2023-01-15 04:23:44 +00:00
|
|
|
|
&repo_path,
|
|
|
|
|
&["config", "set", "--repo", "test-key", "test-val"],
|
|
|
|
|
);
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(
|
2023-01-15 04:23:44 +00:00
|
|
|
|
&repo_path,
|
|
|
|
|
&["config", "set", "--repo", "test-table.foo", "true"],
|
|
|
|
|
);
|
|
|
|
|
// Ensure test-key successfully written to user config.
|
|
|
|
|
let expected_repo_config_path = repo_path.join(".jj/repo/config.toml");
|
|
|
|
|
let repo_config_toml =
|
|
|
|
|
std::fs::read_to_string(&expected_repo_config_path).unwrap_or_else(|_| {
|
|
|
|
|
panic!(
|
|
|
|
|
"Failed to read file {}",
|
|
|
|
|
expected_repo_config_path.display()
|
|
|
|
|
)
|
|
|
|
|
});
|
|
|
|
|
insta::assert_snapshot!(repo_config_toml, @r###"
|
|
|
|
|
test-key = "test-val"
|
|
|
|
|
|
|
|
|
|
[test-table]
|
|
|
|
|
foo = true
|
|
|
|
|
"###);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-11 03:47:46 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_config_set_toml_types() {
|
|
|
|
|
let mut test_env = TestEnvironment::default();
|
2023-10-11 05:02:21 +00:00
|
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
|
2023-10-11 03:47:46 +00:00
|
|
|
|
let user_config_path = test_env.config_path().join("config.toml");
|
|
|
|
|
test_env.set_config_path(user_config_path.clone());
|
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
|
|
|
|
let set_value = |key, value| {
|
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["config", "set", "--user", key, value]);
|
|
|
|
|
};
|
|
|
|
|
set_value("test-table.integer", "42");
|
|
|
|
|
set_value("test-table.float", "3.14");
|
|
|
|
|
set_value("test-table.array", r#"["one", "two"]"#);
|
|
|
|
|
set_value("test-table.boolean", "true");
|
|
|
|
|
set_value("test-table.string", r#""foo""#);
|
|
|
|
|
set_value("test-table.invalid", r"a + b");
|
|
|
|
|
insta::assert_snapshot!(std::fs::read_to_string(&user_config_path).unwrap(), @r###"
|
|
|
|
|
[test-table]
|
|
|
|
|
integer = 42
|
|
|
|
|
float = 3.14
|
|
|
|
|
array = ["one", "two"]
|
|
|
|
|
boolean = true
|
|
|
|
|
string = "foo"
|
|
|
|
|
invalid = "a + b"
|
|
|
|
|
"###);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-15 04:23:44 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_config_set_type_mismatch() {
|
|
|
|
|
let mut test_env = TestEnvironment::default();
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
|
2023-01-15 04:23:44 +00:00
|
|
|
|
let user_config_path = test_env.config_path().join("config.toml");
|
|
|
|
|
test_env.set_config_path(user_config_path);
|
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(
|
2023-01-15 04:23:44 +00:00
|
|
|
|
&repo_path,
|
|
|
|
|
&["config", "set", "--user", "test-table.foo", "test-val"],
|
|
|
|
|
);
|
|
|
|
|
let stderr = test_env.jj_cmd_failure(
|
|
|
|
|
&repo_path,
|
|
|
|
|
&["config", "set", "--user", "test-table", "not-a-table"],
|
|
|
|
|
);
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2023-10-11 05:02:21 +00:00
|
|
|
|
Error: Failed to set test-table: would overwrite entire table
|
2023-01-15 04:23:44 +00:00
|
|
|
|
"###);
|
2023-10-11 05:02:21 +00:00
|
|
|
|
|
|
|
|
|
// But it's fine to overwrite arrays and inline tables
|
|
|
|
|
test_env.jj_cmd_success(
|
|
|
|
|
&repo_path,
|
|
|
|
|
&["config", "set", "--user", "test-table.array", "[1,2,3]"],
|
|
|
|
|
);
|
|
|
|
|
test_env.jj_cmd_success(
|
|
|
|
|
&repo_path,
|
|
|
|
|
&["config", "set", "--user", "test-table.array", "[4,5,6]"],
|
|
|
|
|
);
|
|
|
|
|
test_env.jj_cmd_success(
|
|
|
|
|
&repo_path,
|
|
|
|
|
&["config", "set", "--user", "test-table.inline", "{ x = 42}"],
|
|
|
|
|
);
|
|
|
|
|
test_env.jj_cmd_success(
|
|
|
|
|
&repo_path,
|
|
|
|
|
&["config", "set", "--user", "test-table.inline", "42"],
|
|
|
|
|
);
|
2023-01-15 04:23:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_config_set_nontable_parent() {
|
|
|
|
|
let mut test_env = TestEnvironment::default();
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
|
2023-01-15 04:23:44 +00:00
|
|
|
|
let user_config_path = test_env.config_path().join("config.toml");
|
|
|
|
|
test_env.set_config_path(user_config_path);
|
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(
|
2023-01-15 04:23:44 +00:00
|
|
|
|
&repo_path,
|
|
|
|
|
&["config", "set", "--user", "test-nontable", "test-val"],
|
|
|
|
|
);
|
|
|
|
|
let stderr = test_env.jj_cmd_failure(
|
|
|
|
|
&repo_path,
|
|
|
|
|
&["config", "set", "--user", "test-nontable.foo", "test-val"],
|
|
|
|
|
);
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
|
Error: Failed to set test-nontable.foo: would overwrite non-table value with parent table
|
|
|
|
|
"###);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-05 04:55:20 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_config_edit_missing_opt() {
|
|
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
|
let stderr = test_env.jj_cmd_cli_error(test_env.env_root(), &["config", "edit"]);
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2023-03-17 23:14:20 +00:00
|
|
|
|
error: the following required arguments were not provided:
|
2023-01-05 04:55:20 +00:00
|
|
|
|
<--user|--repo>
|
|
|
|
|
|
|
|
|
|
Usage: jj config edit <--user|--repo>
|
|
|
|
|
|
2023-03-17 23:14:20 +00:00
|
|
|
|
For more information, try '--help'.
|
2023-01-05 04:55:20 +00:00
|
|
|
|
"###);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_config_edit_user() {
|
|
|
|
|
let mut test_env = TestEnvironment::default();
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
|
2023-01-05 04:55:20 +00:00
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
let edit_script = test_env.set_up_fake_editor();
|
|
|
|
|
|
|
|
|
|
std::fs::write(
|
|
|
|
|
edit_script,
|
2023-01-15 04:23:44 +00:00
|
|
|
|
format!("expectpath\n{}", test_env.config_path().to_str().unwrap()),
|
2023-01-05 04:55:20 +00:00
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["config", "edit", "--user"]);
|
2023-01-05 04:55:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_config_edit_repo() {
|
|
|
|
|
let mut test_env = TestEnvironment::default();
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
|
2023-01-05 04:55:20 +00:00
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
let edit_script = test_env.set_up_fake_editor();
|
|
|
|
|
|
|
|
|
|
std::fs::write(
|
|
|
|
|
edit_script,
|
|
|
|
|
format!(
|
|
|
|
|
"expectpath\n{}",
|
|
|
|
|
repo_path.join(".jj/repo/config.toml").to_str().unwrap()
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["config", "edit", "--repo"]);
|
2023-01-05 04:55:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-01 04:53:23 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_config_path() {
|
|
|
|
|
let 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");
|
|
|
|
|
|
|
|
|
|
assert_snapshot!(
|
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["config", "path", "--user"]),
|
|
|
|
|
@r###"
|
|
|
|
|
$TEST_ENV/config
|
|
|
|
|
"###
|
|
|
|
|
);
|
|
|
|
|
assert_snapshot!(
|
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["config", "path", "--repo"]),
|
|
|
|
|
@r###"
|
|
|
|
|
$TEST_ENV/repo/.jj/repo/config.toml
|
|
|
|
|
"###
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-27 00:27:22 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_config_edit_repo_outside_repo() {
|
|
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
|
let stderr = test_env.jj_cmd_failure(test_env.env_root(), &["config", "edit", "--repo"]);
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
|
Error: There is no jj repo in "."
|
|
|
|
|
"###);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-23 18:55:11 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_config_get() {
|
|
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
|
test_env.add_config(
|
2023-08-15 03:18:52 +00:00
|
|
|
|
r#"
|
2023-06-23 18:55:11 +00:00
|
|
|
|
[table]
|
|
|
|
|
string = "some value 1"
|
|
|
|
|
int = 123
|
|
|
|
|
list = ["list", "value"]
|
|
|
|
|
overridden = "foo"
|
2023-08-15 03:18:52 +00:00
|
|
|
|
"#,
|
2023-06-23 18:55:11 +00:00
|
|
|
|
);
|
|
|
|
|
test_env.add_config(
|
2023-08-15 03:18:52 +00:00
|
|
|
|
r#"
|
2023-06-23 18:55:11 +00:00
|
|
|
|
[table]
|
|
|
|
|
overridden = "bar"
|
2023-08-15 03:18:52 +00:00
|
|
|
|
"#,
|
2023-06-23 18:55:11 +00:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let stdout = test_env.jj_cmd_failure(test_env.env_root(), &["config", "get", "nonexistent"]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
Config error: configuration property "nonexistent" not found
|
|
|
|
|
For help, see https://github.com/martinvonz/jj/blob/main/docs/config.md.
|
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
let stdout = test_env.jj_cmd_success(test_env.env_root(), &["config", "get", "table.string"]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
some value 1
|
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
let stdout = test_env.jj_cmd_success(test_env.env_root(), &["config", "get", "table.int"]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
123
|
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
For help, see https://github.com/martinvonz/jj/blob/main/docs/config.md.
|
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
let stdout =
|
|
|
|
|
test_env.jj_cmd_success(test_env.env_root(), &["config", "get", "table.overridden"]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @"bar");
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-13 06:22:08 +00:00
|
|
|
|
fn find_stdout_lines(keyname_pattern: &str, stdout: &str) -> String {
|
2023-01-02 07:05:41 +00:00
|
|
|
|
let key_line_re = Regex::new(&format!(r"(?m)^{keyname_pattern}=.*$")).unwrap();
|
2022-12-13 06:22:08 +00:00
|
|
|
|
key_line_re
|
|
|
|
|
.find_iter(stdout)
|
|
|
|
|
.map(|m| m.as_str())
|
|
|
|
|
.collect_vec()
|
|
|
|
|
.join("\n")
|
|
|
|
|
}
|