diff options
-rw-r--r-- | github-suggestion/src/suggestion.rs | 22 | ||||
-rw-r--r-- | src/bin/git-sugdiff.rs | 6 |
2 files changed, 24 insertions, 4 deletions
diff --git a/github-suggestion/src/suggestion.rs b/github-suggestion/src/suggestion.rs index 21591b1..29fab04 100644 --- a/github-suggestion/src/suggestion.rs +++ b/github-suggestion/src/suggestion.rs @@ -157,7 +157,27 @@ impl Suggestion { message: "unable to read right side of patch".to_owned(), })?; - Ok(repo.blob(&new_buffer)?) + let mut index = repo.index()?; + index.add_frombuffer( + &git2::IndexEntry { + ctime: git2::IndexTime::new(0, 0), + mtime: git2::IndexTime::new(0, 0), + dev: 0, + ino: 0, + mode: 0o100644, + uid: 0, + gid: 0, + file_size: new_buffer.len() as u32, + id: git2::Oid::zero(), + flags: 0, + flags_extended: 0, + path: self.path.as_bytes().to_vec(), + }, + &new_buffer, + )?; + let tree = index.write_tree()?; + + Ok(tree) } /// Extract suggestion code from a comment body. diff --git a/src/bin/git-sugdiff.rs b/src/bin/git-sugdiff.rs index 9c7ff1f..362eb15 100644 --- a/src/bin/git-sugdiff.rs +++ b/src/bin/git-sugdiff.rs @@ -43,12 +43,12 @@ fn main() { &config, |suggestion| { // TODO: Needs to work for multiple suggestions at once - let blob = suggestion.diff_command().unwrap(); + let tree = suggestion.diff_command().unwrap(); Command::new("git") .arg("diff") - .arg(format!("{}:{}", suggestion.commit(), suggestion.path())) - .arg(blob.to_string()) + .arg(suggestion.commit()) + .arg(tree.to_string()) .spawn() .unwrap(); }, |