Insert changes from one view to another.
(repo: &Repository, args: &FromViewArgs)
| 238 | |
| 239 | /// Insert changes from one view to another. |
| 240 | fn run_from_view(repo: &Repository, args: &FromViewArgs) -> CliResult<()> { |
| 241 | let to_view = args |
| 242 | .to_view |
| 243 | .clone() |
| 244 | .unwrap_or_else(|| repo.current_view().to_string()); |
| 245 | let is_current_view = to_view == repo.current_view(); |
| 246 | |
| 247 | output::print_info(&format!( |
| 248 | "Inserting changes from '{}' to '{}'...", |
| 249 | args.from_view, to_view |
| 250 | )); |
| 251 | |
| 252 | let options = CrossViewInsertOptions::new(&args.from_view, &to_view) |
| 253 | .with_dependencies(args.deps) |
| 254 | .allow_conflicts(args.allow_conflicts) |
| 255 | .dry_run(args.dry_run); |
| 256 | |
| 257 | let outcome = repo |
| 258 | .insert_from_view(options) |
| 259 | .map_err(|e| CliError::Conflict { |
| 260 | description: e.to_string(), |
| 261 | })?; |
| 262 | |
| 263 | print_cross_view_outcome(&outcome, args.dry_run); |
| 264 | |
| 265 | // Update working copy if we inserted into the current view. |
| 266 | // Collect affected file paths from the inserted changes and only |
| 267 | // materialize those, avoiding a full rematerialization of the |
| 268 | // entire working copy. |
| 269 | if is_current_view && !args.dry_run && outcome.changes_applied > 0 { |
| 270 | let spinner = output::create_spinner("Materializing files for view..."); |
| 271 | |
| 272 | let mut affected_paths = std::collections::HashSet::new(); |
| 273 | for hash in &outcome.applied_hashes { |
| 274 | if let Ok(change) = repo.load_change(hash) { |
| 275 | for op in change.hunks() { |
| 276 | if let Some(p) = op.path() { |
| 277 | affected_paths.insert(p.to_string()); |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | let output_result = if affected_paths.is_empty() { |
| 284 | // No path info available (e.g. AddRoot-only changes) — |
| 285 | // fall back to full materialize. |
| 286 | repo.materialize().map_err(|e| { |
| 287 | CliError::Internal(anyhow::anyhow!("Failed to update working copy: {}", e)) |
| 288 | })? |
| 289 | } else { |
| 290 | repo.materialize_paths(affected_paths).map_err(|e| { |
| 291 | CliError::Internal(anyhow::anyhow!("Failed to update working copy: {}", e)) |
| 292 | })? |
| 293 | }; |
| 294 | |
| 295 | output::finish_success( |
| 296 | &spinner, |
| 297 | &format!( |
no test coverage detected