Insert a single change by hash.
(repo: &Repository, change_str: &str, args: &Insert)
| 216 | |
| 217 | /// Insert a single change by hash. |
| 218 | fn run_single_insert(repo: &Repository, change_str: &str, args: &Insert) -> CliResult<()> { |
| 219 | let hash = parse_change_hash(repo, change_str)?; |
| 220 | let is_current_view = args.view.is_none() || args.view.as_deref() == Some(repo.current_view()); |
| 221 | |
| 222 | let options = InsertOptions::default() |
| 223 | .apply_deps(args.deps) |
| 224 | .allow_conflict(args.allow_conflicts); |
| 225 | |
| 226 | let options = if let Some(ref view) = args.view { |
| 227 | options.view(view) |
| 228 | } else { |
| 229 | options |
| 230 | }; |
| 231 | |
| 232 | output::print_info(&format!("Inserting change {}...", format_hash(&hash, true))); |
| 233 | |
| 234 | let outcome = if args.deps { |
| 235 | repo.insert_change_rec(&hash, options) |
| 236 | } else { |
| 237 | repo.insert_change(&hash, options) |
| 238 | } |
| 239 | .map_err(|e| CliError::Conflict { |
| 240 | description: e.to_string(), |
| 241 | })?; |
| 242 | |
| 243 | print_insert_outcome( |
| 244 | &outcome.stats.applied_hashes, |
| 245 | outcome.new_state, |
| 246 | outcome.has_conflicts, |
| 247 | ); |
| 248 | |
| 249 | // Update working copy if we inserted into the current view |
| 250 | if is_current_view && !outcome.stats.applied_hashes.is_empty() { |
| 251 | let output_result = repo.materialize().map_err(|e| { |
| 252 | CliError::Internal(anyhow::anyhow!("Failed to update working copy: {}", e)) |
| 253 | })?; |
| 254 | output::print_success(&format!( |
| 255 | "{} files updated, {} directories", |
| 256 | output_result.files_written, output_result.directories_created |
| 257 | )); |
| 258 | print_conflict_summary(repo); |
| 259 | } |
| 260 | |
| 261 | Ok(()) |
| 262 | } |
| 263 | |
| 264 | /// Promote the current view's changes into its parent view. |
| 265 | /// |
no test coverage detected