| 1 |
// Copyright 2020 The Jujutsu Authors |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
use std::io::Write as _; |
| 16 |
|
| 17 |
use jj_lib::file_util; |
| 18 |
use jj_lib::workspace::Workspace; |
| 19 |
use tracing::instrument; |
| 20 |
|
| 21 |
use crate::cli_util::CommandHelper; |
| 22 |
use crate::command_error::CommandError; |
| 23 |
use crate::command_error::cli_error; |
| 24 |
use crate::command_error::user_error_with_message; |
| 25 |
use crate::ui::Ui; |
| 26 |
|
| 27 |
/// Create a new repo in the given directory using the proof-of-concept simple |
| 28 |
/// backend |
| 29 |
/// |
| 30 |
/// The simple backend does not support cloning, fetching, or pushing. |
| 31 |
/// |
| 32 |
/// This command is otherwise analogous to `jj git init`. If the given directory |
| 33 |
/// does not exist, it will be created. If no directory is given, the current |
| 34 |
/// directory is used. |
| 35 |
#[derive(clap::Args, Clone, Debug)] |
| 36 |
pub(crate) struct DebugInitSimpleArgs { |
| 37 |
/// The destination directory |
| 38 |
#[arg(default_value = ".", value_hint = clap::ValueHint::DirPath)] |
| 39 |
destination: String, |
| 40 |
} |
| 41 |
|
| 42 |
#[instrument(skip_all)] |
| 43 |
pub(crate) async fn cmd_debug_init_simple( |
| 44 |
ui: &mut Ui, |
| 45 |
command: &CommandHelper, |
| 46 |
args: &DebugInitSimpleArgs, |
| 47 |
) -> Result<(), CommandError> { |
| 48 |
if command.global_args().no_integrate_operation { |
| 49 |
return Err(cli_error("--no-integrate-operation is not respected")); |
| 50 |
} |
| 51 |
if command.global_args().ignore_working_copy { |
| 52 |
return Err(cli_error("--ignore-working-copy is not respected")); |
| 53 |
} |
| 54 |
if command.global_args().at_operation.is_some() { |
| 55 |
return Err(cli_error("--at-op is not respected")); |
| 56 |
} |
| 57 |
let cwd = command.cwd(); |
| 58 |
let wc_path = cwd.join(&args.destination); |
| 59 |
let wc_path = file_util::create_or_reuse_dir(&wc_path) |
| 60 |
.and_then(|_| dunce::canonicalize(wc_path)) |
| 61 |
.map_err(|e| user_error_with_message("Failed to create workspace", e))?; |
| 62 |
|
| 63 |
Workspace::init_simple( |
| 64 |
&command.settings_for_new_workspace(ui, &wc_path)?.0, |
| 65 |
&wc_path, |
| 66 |
) |
| 67 |
.await?; |
| 68 |
|
| 69 |
let relative_wc_path = file_util::relative_path(cwd, &wc_path); |
| 70 |
writeln!( |
| 71 |
ui.status(), |
| 72 |
"Initialized repo in \"{}\"", |
| 73 |
relative_wc_path.display() |
| 74 |
)?; |
| 75 |
Ok(()) |
| 76 |
} |