Async implementation of the clone command. This is the main entry point for the clone operation. It coordinates all the steps required to create a local copy of a remote repository.
(&self)
| 457 | /// This is the main entry point for the clone operation. It coordinates |
| 458 | /// all the steps required to create a local copy of a remote repository. |
| 459 | async fn run_async(&self) -> CliResult<()> { |
| 460 | // Resolve target path |
| 461 | let target_path = resolve_target_path(&self.url, self.path.clone()); |
| 462 | let display_name = self.get_display_name(); |
| 463 | |
| 464 | // Print header |
| 465 | println!( |
| 466 | "Cloning from {} into {}...", |
| 467 | hint(&self.url), |
| 468 | style_view(&display_name) |
| 469 | ); |
| 470 | print_blank(); |
| 471 | |
| 472 | let guard = if self.into_existing { |
| 473 | validate_existing_git_checkout(&target_path)?; |
| 474 | None |
| 475 | } else { |
| 476 | validate_target_path(&target_path)?; |
| 477 | std::fs::create_dir_all(&target_path).map_err(|e| CliError::InvalidPath { |
| 478 | path: target_path.clone(), |
| 479 | source: Some(e), |
| 480 | })?; |
| 481 | Some(CleanupGuard::new(target_path.clone())) |
| 482 | }; |
| 483 | |
| 484 | // Initialize repository |
| 485 | let spinner = create_spinner("Initializing repository..."); |
| 486 | let mut repo = Repository::init(&target_path).map_err(|e| { |
| 487 | finish_error(&spinner, "Failed to initialize"); |
| 488 | CliError::Repository(e) |
| 489 | })?; |
| 490 | finish_success(&spinner, "Repository initialized"); |
| 491 | |
| 492 | // Clone must insert remote changes into the requested local view, |
| 493 | // rather than whichever default view repository initialization chose. |
| 494 | if !repo.view_exists(&self.view).map_err(CliError::Repository)? { |
| 495 | repo.create_shared_view(&self.view) |
| 496 | .map_err(CliError::Repository)?; |
| 497 | } |
| 498 | repo.align_to_view(&self.view) |
| 499 | .map_err(CliError::Repository)?; |
| 500 | |
| 501 | // Connect to remote |
| 502 | let spinner = create_spinner("Connecting to remote..."); |
| 503 | let config = self.build_remote_config().await; |
| 504 | let remote = HttpRemote::with_config(&self.url, config).map_err(|e| { |
| 505 | finish_error(&spinner, "Failed to connect"); |
| 506 | convert_remote_error(e, &self.url) |
| 507 | })?; |
| 508 | finish_success(&spinner, "Connected"); |
| 509 | |
| 510 | // Query remote state |
| 511 | let spinner = create_spinner("Querying remote state..."); |
| 512 | let remote_state = remote.get_state(&self.view).await.map_err(|e| { |
| 513 | finish_error(&spinner, "Failed to query state"); |
| 514 | convert_remote_error(e, &self.url) |
| 515 | })?; |
| 516 |
no test coverage detected