aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTeddy Wing2020-07-24 00:41:19 +0200
committerTeddy Wing2020-07-24 00:42:53 +0200
commit4d89f0c16c61175042c47b493cb945618db8f72b (patch)
treec2cd94703719000037e56ff9cf5498ee3ed3f305 /src
parent55894d54c19d8eed751ef31b66698c0a85997cee (diff)
downloadgit-suggestion-4d89f0c16c61175042c47b493cb945618db8f72b.tar.bz2
Read a blob from a repository
Work out the code required to get a file blob's contents from a Git repository using the 'git2' crate. We'll be using this to get the original file for patching.
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index f65b637..fe945be 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -204,4 +204,26 @@ mod tests {
fn patches_file() {
// File::open("../testdata/");
}
+
+ #[test]
+ fn read_git_blob() {
+ use std::path::Path;
+
+ use git2::Repository;
+
+ let repo = Repository::open("./private/suggestion-test").unwrap();
+ let commit = repo.find_commit("b58be52880a0a0c0d397052351be31f19acdeca4".parse().unwrap()).unwrap();
+
+ let object = commit
+ .tree().unwrap()
+ .get_path(Path::new("src/server.rs")).unwrap()
+ .to_object(&repo).unwrap();
+
+ let blob = object
+ .as_blob().unwrap()
+ .content();
+
+ println!("{:?}", commit);
+ println!("{}", std::str::from_utf8(blob).unwrap());
+ }
}