diff --git a/src/commands.rs b/src/commands.rs index a9404a11d..6e0f5e99e 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -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(()) } diff --git a/tests/test_init_command.rs b/tests/test_init_command.rs index 5fe88e276..0a98e7299 100644 --- a/tests/test_init_command.rs +++ b/tests/test_init_command.rs @@ -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();