just playing with tangled
at gvimdiff 69 lines 2.4 kB view raw
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 15use std::io::Write as _; 16 17use jj_lib::file_util; 18use jj_lib::workspace::Workspace; 19use tracing::instrument; 20 21use crate::cli_util::CommandHelper; 22use crate::command_error::cli_error; 23use crate::command_error::user_error_with_message; 24use crate::command_error::CommandError; 25use 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)] 36pub(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)] 43pub(crate) fn cmd_debug_init_simple( 44 ui: &mut Ui, 45 command: &CommandHelper, 46 args: &DebugInitSimpleArgs, 47) -> Result<(), CommandError> { 48 if command.global_args().ignore_working_copy { 49 return Err(cli_error("--ignore-working-copy is not respected")); 50 } 51 if command.global_args().at_operation.is_some() { 52 return Err(cli_error("--at-op is not respected")); 53 } 54 let cwd = command.cwd(); 55 let wc_path = cwd.join(&args.destination); 56 let wc_path = file_util::create_or_reuse_dir(&wc_path) 57 .and_then(|_| dunce::canonicalize(wc_path)) 58 .map_err(|e| user_error_with_message("Failed to create workspace", e))?; 59 60 Workspace::init_simple(&command.settings_for_new_workspace(&wc_path)?, &wc_path)?; 61 62 let relative_wc_path = file_util::relative_path(cwd, &wc_path); 63 writeln!( 64 ui.status(), 65 "Initialized repo in \"{}\"", 66 relative_wc_path.display() 67 )?; 68 Ok(()) 69}