(
&self,
request: Request<AddFilesRequest>,
)
| 1407 | #[tonic::async_trait] |
| 1408 | impl repository_mutation_service_server::RepositoryMutationService for MutationImpl { |
| 1409 | async fn add_files( |
| 1410 | &self, |
| 1411 | request: Request<AddFilesRequest>, |
| 1412 | ) -> Result<Response<AddFilesResponse>, Status> { |
| 1413 | let request = request.into_inner(); |
| 1414 | let handle = self |
| 1415 | .state |
| 1416 | .resolve(request.repository.as_ref().unwrap_or(&default_ref()))?; |
| 1417 | self.state.log_rpc("AddFiles", Some(&handle)); |
| 1418 | let gate_handle = handle.clone(); |
| 1419 | let _gate = gate_handle.exclusive().await; |
| 1420 | let paths: Vec<String> = request.paths; |
| 1421 | let meta = request.meta.unwrap_or_default(); |
| 1422 | let options = TrackingOptions { |
| 1423 | recursive: !request.no_recursive, |
| 1424 | force: request.force, |
| 1425 | dry_run: request.dry_run, |
| 1426 | ..TrackingOptions::default() |
| 1427 | }; |
| 1428 | let directory = request.directory; |
| 1429 | let dry_run = request.dry_run; |
| 1430 | let result = tokio::task::spawn_blocking(move || { |
| 1431 | let (repo, workspace) = handle.workspace_repository(if dry_run { |
| 1432 | atomic_repository::WorkspaceTxnMode::Observe |
| 1433 | } else { |
| 1434 | atomic_repository::WorkspaceTxnMode::Reconcile |
| 1435 | })?; |
| 1436 | let working_copy = workspace.working_copy(); |
| 1437 | let mut tracked = 0usize; |
| 1438 | // The tolerant per-path report (dry-run or not): skips never |
| 1439 | // fail the batch; failures are collected per path. |
| 1440 | let mut would_add: Vec<String> = Vec::new(); |
| 1441 | let mut skipped_tracked: Vec<String> = Vec::new(); |
| 1442 | let mut skipped_ignored: Vec<String> = Vec::new(); |
| 1443 | let mut failed_paths: Vec<String> = Vec::new(); |
| 1444 | for path in &paths { |
| 1445 | let result = if directory { |
| 1446 | repo.add_directory(working_copy, path, options.clone()) |
| 1447 | } else { |
| 1448 | repo.add(working_copy, path, options.clone()) |
| 1449 | }; |
| 1450 | match result { |
| 1451 | Ok(stats) => { |
| 1452 | if dry_run { |
| 1453 | if stats.total_added() > 0 { |
| 1454 | would_add.push(path.clone()); |
| 1455 | } |
| 1456 | for (skipped, reason) in &stats.skipped_paths { |
| 1457 | if reason.contains("tracked") { |
| 1458 | skipped_tracked.push(skipped.to_string_lossy().into_owned()); |
| 1459 | } else if reason.contains("ignored") { |
| 1460 | skipped_ignored.push(skipped.to_string_lossy().into_owned()); |
| 1461 | } |
| 1462 | } |
| 1463 | } else { |
| 1464 | tracked += stats.files_added; |
| 1465 | } |
| 1466 | } |
no test coverage detected