Execute stash clear.
(&self, repo: &mut Repository, force: bool)
| 412 | |
| 413 | /// Execute stash clear. |
| 414 | fn run_clear(&self, repo: &mut Repository, force: bool) -> CliResult<()> { |
| 415 | if !force { |
| 416 | let count = repo |
| 417 | .stash_list() |
| 418 | .map_err(|message| CliError::Internal(anyhow::anyhow!(message)))? |
| 419 | .len(); |
| 420 | if count == 0 { |
| 421 | println!("No stashes to clear"); |
| 422 | return Ok(()); |
| 423 | } |
| 424 | println!("This will delete {count} stash(es). Are you sure? [y/N] "); |
| 425 | std::io::Write::flush(&mut std::io::stdout()).ok(); |
| 426 | let mut input = String::new(); |
| 427 | std::io::stdin().read_line(&mut input).ok(); |
| 428 | if !input.trim().eq_ignore_ascii_case("y") { |
| 429 | println!("Aborted"); |
| 430 | return Ok(()); |
| 431 | } |
| 432 | } |
| 433 | let count = repo |
| 434 | .stash_clear() |
| 435 | .map_err(|message| CliError::InvalidArgument { message })?; |
| 436 | if count == 0 { |
| 437 | println!("No stashes to clear"); |
| 438 | } else { |
| 439 | print_success(&format!("Cleared {count} stash(es)")); |
| 440 | } |
| 441 | Ok(()) |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | impl Default for Stash { |
no test coverage detected