Insert a single change by hash.
(repo: &Repository, change_str: &str, args: &Insert)
| 192 | |
| 193 | /// Insert a single change by hash. |
| 194 | fn run_single_insert(repo: &Repository, change_str: &str, args: &Insert) -> CliResult<()> { |
| 195 | let hash = parse_change_hash(repo, change_str)?; |
| 196 | let is_current_view = args.view.is_none() || args.view.as_deref() == Some(repo.current_view()); |
| 197 | |
| 198 | let options = InsertOptions::default() |
| 199 | .apply_deps(args.deps) |
| 200 | .allow_conflict(args.allow_conflicts); |
| 201 | |
| 202 | let options = if let Some(ref view) = args.view { |
| 203 | options.view(view) |
| 204 | } else { |
| 205 | options |
| 206 | }; |
| 207 | |
| 208 | output::print_info(&format!("Inserting change {}...", format_hash(&hash, true))); |
| 209 | |
| 210 | let outcome = if args.deps { |
| 211 | repo.insert_change_rec(&hash, options) |
| 212 | } else { |
| 213 | repo.insert_change(&hash, options) |
| 214 | } |
| 215 | .map_err(|e| CliError::Conflict { |
| 216 | description: e.to_string(), |
| 217 | })?; |
| 218 | |
| 219 | print_insert_outcome( |
| 220 | &outcome.stats.applied_hashes, |
| 221 | outcome.new_state, |
| 222 | outcome.has_conflicts, |
| 223 | ); |
| 224 | |
| 225 | // Update working copy if we inserted into the current view |
| 226 | if is_current_view && !outcome.stats.applied_hashes.is_empty() { |
| 227 | let output_result = repo.materialize().map_err(|e| { |
| 228 | CliError::Internal(anyhow::anyhow!("Failed to update working copy: {}", e)) |
| 229 | })?; |
| 230 | output::print_success(&format!( |
| 231 | "{} files updated, {} directories", |
| 232 | output_result.files_written, output_result.directories_created |
| 233 | )); |
| 234 | } |
| 235 | |
| 236 | Ok(()) |
| 237 | } |
| 238 | |
| 239 | /// Insert changes from one view to another. |
| 240 | fn run_from_view(repo: &Repository, args: &FromViewArgs) -> CliResult<()> { |
no test coverage detected