cli: suggest 'jj init --git-repo' if .git directory already exists

I made new empty repository by mistake, and didn't notice it until I ran
'jj status'.
This commit is contained in:
Yuya Nishihara 2022-10-29 19:02:41 +09:00
parent 7947ba16f1
commit 55184237e1
2 changed files with 26 additions and 1 deletions

View file

@ -1125,6 +1125,13 @@ Set `ui.allow-init-native` to allow initializing a repo with the native backend.
let cwd = ui.cwd().canonicalize().unwrap();
let relative_wc_path = file_util::relative_path(&cwd, &wc_path);
writeln!(ui, "Initialized repo in \"{}\"", relative_wc_path.display())?;
if args.git && wc_path.join(".git").exists() {
ui.write_warn(format!(
"Empty repo created. To create repo backed by existing Git repo, run `jj init \
--git-repo={}` instead.\n",
relative_wc_path.display()
))?;
}
Ok(())
}

View file

@ -14,7 +14,7 @@
use std::path::PathBuf;
use crate::common::TestEnvironment;
use crate::common::{get_stderr_string, get_stdout_string, TestEnvironment};
pub mod common;
@ -143,6 +143,24 @@ fn test_init_git_colocated() {
"###);
}
#[test]
fn test_init_git_internal_but_could_be_colocated() {
let test_env = TestEnvironment::default();
let workspace_root = test_env.env_root().join("repo");
init_git_repo(&workspace_root);
let assert = test_env
.jj_cmd(&workspace_root, &["init", "--git"])
.assert()
.success();
insta::assert_snapshot!(get_stdout_string(&assert), @r###"
Initialized repo in "."
"###);
insta::assert_snapshot!(get_stderr_string(&assert), @r###"
Empty repo created. To create repo backed by existing Git repo, run `jj init --git-repo=.` instead.
"###);
}
#[test]
fn test_init_local_disallowed() {
let test_env = TestEnvironment::default();