(
connection_state: state::Connection,
ancestor_sha: String,
descendant_sha: String,
)
| 22 | } |
| 23 | |
| 24 | pub fn dispatch( |
| 25 | connection_state: state::Connection, |
| 26 | ancestor_sha: String, |
| 27 | descendant_sha: String, |
| 28 | ) -> DispatchFuture { |
| 29 | use self::ErrorReason::{AncestorMustBeASha, DescendantMustBeASha, RepoPathNotSet, |
| 30 | ShaIsNotACommit}; |
| 31 | use error::protocol::{Error, ProcessError::Failed}; |
| 32 | |
| 33 | if !git::verify_string_is_sha(&ancestor_sha) { |
| 34 | return Box::new(send_message( |
| 35 | connection_state, |
| 36 | OutboundMessage::Error(AncestorMustBeASha), |
| 37 | )); |
| 38 | } |
| 39 | |
| 40 | if !git::verify_string_is_sha(&descendant_sha) { |
| 41 | return Box::new(send_message( |
| 42 | connection_state, |
| 43 | OutboundMessage::Error(DescendantMustBeASha), |
| 44 | )); |
| 45 | } |
| 46 | |
| 47 | match connection_state.repo_path.clone() { |
| 48 | Some(repo_path) => Box::new( |
| 49 | git::new_command_with_repo_path(&repo_path) |
| 50 | .arg("merge-base") |
| 51 | .arg("--is-ancestor") |
| 52 | .arg(ancestor_sha) |
| 53 | .arg(descendant_sha) |
| 54 | .output_async() // NOTE we should parse error messages someday |
| 55 | .then(|result| match result { |
| 56 | Ok(output) => match output.status.code() { |
| 57 | Some(status) => future::ok((status, connection_state)), |
| 58 | None => future::err((Error::Process(Failed), connection_state)), |
| 59 | }, |
| 60 | Err(_) => future::err((Error::Process(Failed), connection_state)), |
| 61 | }) |
| 62 | .and_then(|(status, connection_state)| -> DispatchFuture { |
| 63 | Box::new(send_message( |
| 64 | connection_state, |
| 65 | if status == 0 || status == 1 { |
| 66 | OutboundMessage::Success { is_ancestor: status == 0 } |
| 67 | } else { |
| 68 | OutboundMessage::Error(ShaIsNotACommit) |
| 69 | } |
| 70 | )) |
| 71 | }), |
| 72 | ), |
| 73 | None => Box::new(send_message( |
| 74 | connection_state, |
| 75 | OutboundMessage::Error(RepoPathNotSet), |
| 76 | )), |
| 77 | } |
| 78 | } |
nothing calls this directly
no test coverage detected