use std::io::Write as _;
use jj_lib::file_util;
use jj_lib::workspace::Workspace;
use tracing::instrument;
use crate::cli_util::CommandHelper;
use crate::command_error::CommandError;
use crate::command_error::cli_error;
use crate::command_error::user_error_with_message;
use crate::ui::Ui;
#[derive(clap::Args, Clone, Debug)]
pub(crate) struct DebugInitSimpleArgs {
#[arg(default_value = ".", value_hint = clap::ValueHint::DirPath)]
destination: String,
}
#[instrument(skip_all)]
pub(crate) async fn cmd_debug_init_simple(
ui: &mut Ui,
command: &CommandHelper,
args: &DebugInitSimpleArgs,
) -> Result<(), CommandError> {
if command.global_args().no_integrate_operation {
return Err(cli_error("--no-integrate-operation is not respected"));
}
if command.global_args().ignore_working_copy {
return Err(cli_error("--ignore-working-copy is not respected"));
}
if command.global_args().at_operation.is_some() {
return Err(cli_error("--at-op is not respected"));
}
let cwd = command.cwd();
let wc_path = cwd.join(&args.destination);
let wc_path = file_util::create_or_reuse_dir(&wc_path)
.and_then(|_| dunce::canonicalize(wc_path))
.map_err(|e| user_error_with_message("Failed to create workspace", e))?;
Workspace::init_simple(
&command.settings_for_new_workspace(ui, &wc_path)?.0,
&wc_path,
)
.await?;
let relative_wc_path = file_util::relative_path(cwd, &wc_path);
writeln!(
ui.status(),
"Initialized repo in \"{}\"",
relative_wc_path.display()
)?;
Ok(())
}