(repo: &Repository, prefix: &str)
| 628 | } |
| 629 | |
| 630 | fn resolve_by_prefix(repo: &Repository, prefix: &str) -> CliResult<GitStateBinding> { |
| 631 | let lower = prefix.to_ascii_lowercase(); |
| 632 | let ids = repo.binding_ids().map_err(CliError::from)?; |
| 633 | let matches: Vec<_> = ids |
| 634 | .iter() |
| 635 | .filter(|id| id.to_hex().starts_with(&lower)) |
| 636 | .collect(); |
| 637 | match matches.as_slice() { |
| 638 | [id] => repo |
| 639 | .load_binding(id) |
| 640 | .map_err(CliError::from)? |
| 641 | .ok_or_else(|| { |
| 642 | CliError::Repository(atomic_repository::RepositoryError::InvalidOperation { |
| 643 | message: format!("binding {prefix} is not stored locally"), |
| 644 | }) |
| 645 | }), |
| 646 | [] => Err(CliError::Repository( |
| 647 | atomic_repository::RepositoryError::InvalidOperation { |
| 648 | message: format!("binding prefix {prefix} matches nothing"), |
| 649 | }, |
| 650 | )), |
| 651 | many => Err(CliError::Repository( |
| 652 | atomic_repository::RepositoryError::InvalidOperation { |
| 653 | message: format!( |
| 654 | "binding prefix {prefix} is ambiguous: {} matches", |
| 655 | matches.len() |
| 656 | ), |
| 657 | }, |
| 658 | )), |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | fn git_map(error: impl std::fmt::Display) -> CliError { |
| 663 | CliError::Repository(atomic_repository::RepositoryError::InvalidOperation { |
no test coverage detected