mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-18 02:04:19 +00:00
cli: disallow initializing repo with native backend by default
The native backend is just a proof of concept and there's no real reason to use it other than for testing, so let's reduce the risk of accidentally creating repos using it.
This commit is contained in:
parent
832457d4a5
commit
043d118f1f
4 changed files with 38 additions and 0 deletions
|
@ -100,6 +100,12 @@ impl UserSettings {
|
|||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
pub fn allow_native_backend(&self) -> bool {
|
||||
self.config
|
||||
.get_bool("ui.allow-init-native")
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
pub fn config(&self) -> &config::Config {
|
||||
&self.config
|
||||
}
|
||||
|
|
|
@ -1097,6 +1097,13 @@ fn cmd_init(ui: &mut Ui, command: &CommandHelper, args: &InitArgs) -> Result<(),
|
|||
} else if args.git {
|
||||
Workspace::init_internal_git(ui.settings(), &wc_path)?;
|
||||
} else {
|
||||
if !ui.settings().allow_native_backend() {
|
||||
return Err(CommandError::UserError(
|
||||
"The native backend is disallowed by default. Did you mean to pass `--git`?
|
||||
Set `ui.allow-init-native` to allow initializing a repo with the native backend."
|
||||
.to_string(),
|
||||
));
|
||||
}
|
||||
Workspace::init_local(ui.settings(), &wc_path)?;
|
||||
};
|
||||
let cwd = ui.cwd().canonicalize().unwrap();
|
||||
|
|
|
@ -143,9 +143,24 @@ fn test_init_git_colocated() {
|
|||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_init_local_disallowed() {
|
||||
let test_env = TestEnvironment::default();
|
||||
let stdout = test_env.jj_cmd_failure(test_env.env_root(), &["init", "repo"]);
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
Error: The native backend is disallowed by default. Did you mean to pass `--git`?
|
||||
Set `ui.allow-init-native` to allow initializing a repo with the native backend.
|
||||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_init_local() {
|
||||
let test_env = TestEnvironment::default();
|
||||
test_env.add_config(
|
||||
br#"[ui]
|
||||
allow-init-native = true
|
||||
"#,
|
||||
);
|
||||
let stdout = test_env.jj_cmd_success(test_env.env_root(), &["init", "repo"]);
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
Initialized repo in "repo"
|
||||
|
|
|
@ -21,6 +21,11 @@ pub mod common;
|
|||
#[test]
|
||||
fn test_untrack() {
|
||||
let test_env = TestEnvironment::default();
|
||||
test_env.add_config(
|
||||
br#"[ui]
|
||||
allow-init-native = true
|
||||
"#,
|
||||
);
|
||||
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo"]);
|
||||
let repo_path = test_env.env_root().join("repo");
|
||||
|
||||
|
@ -88,6 +93,11 @@ fn test_untrack() {
|
|||
#[test]
|
||||
fn test_untrack_sparse() {
|
||||
let test_env = TestEnvironment::default();
|
||||
test_env.add_config(
|
||||
br#"[ui]
|
||||
allow-init-native = true
|
||||
"#,
|
||||
);
|
||||
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo"]);
|
||||
let repo_path = test_env.env_root().join("repo");
|
||||
|
||||
|
|
Loading…
Reference in a new issue