diff options
| -rw-r--r-- | github-suggestion/src/suggestion.rs | 24 | ||||
| -rw-r--r-- | src/bin/git-sugdiff.rs | 10 | 
2 files changed, 19 insertions, 15 deletions
| diff --git a/github-suggestion/src/suggestion.rs b/github-suggestion/src/suggestion.rs index 3f124ce..21591b1 100644 --- a/github-suggestion/src/suggestion.rs +++ b/github-suggestion/src/suggestion.rs @@ -16,7 +16,6 @@  use std::io::{BufRead, BufReader, BufWriter, Write};  use std::path::Path; -use std::process::Command;  use git2::{Patch, Repository};  use regex::Regex; @@ -81,6 +80,14 @@ pub struct Suggestion {  }  impl Suggestion { +    pub fn commit(&self) -> &str { +        &self.commit +    } + +    pub fn path(&self) -> &str { +        &self.path +    } +      /// Get the suggestion diff for the current repository.      pub fn diff(&self) -> Result<String, Error> {          let repo = Repository::open(".")?; @@ -127,7 +134,7 @@ impl Suggestion {          )      } -    pub fn diff_command(&self) -> Result<(), Error> { +    pub fn diff_command(&self) -> Result<git2::Oid, Error> {          let repo = Repository::open(".")?;          let commit = repo.find_commit(self.commit.parse()?)?; @@ -150,18 +157,7 @@ impl Suggestion {                  message: "unable to read right side of patch".to_owned(),              })?; -        let patched_blob = repo.blob(&new_buffer)?; - -        Command::new("git") -            .arg("diff") -            .arg(format!("{}:{}", commit.id(), self.path)) -            .arg(patched_blob.to_string()) -            .spawn() -            .unwrap(); - -        // Maybe: Return blob - -        Ok(()) +        Ok(repo.blob(&new_buffer)?)      }      /// Extract suggestion code from a comment body. diff --git a/src/bin/git-sugdiff.rs b/src/bin/git-sugdiff.rs index c8ecf40..9c7ff1f 100644 --- a/src/bin/git-sugdiff.rs +++ b/src/bin/git-sugdiff.rs @@ -16,6 +16,7 @@  use std::env;  use std::process; +use std::process::Command;  use exitcode; @@ -42,7 +43,14 @@ fn main() {          &config,          |suggestion| {              // TODO: Needs to work for multiple suggestions at once -            suggestion.diff_command().unwrap(); +            let blob = suggestion.diff_command().unwrap(); + +            Command::new("git") +                .arg("diff") +                .arg(format!("{}:{}", suggestion.commit(), suggestion.path())) +                .arg(blob.to_string()) +                .spawn() +                .unwrap();          },      );  } | 
