summaryrefslogtreecommitdiff
path: root/src/repository.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/repository.rs')
-rw-r--r--src/repository.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/repository.rs b/src/repository.rs
index f5ecffb..97b7816 100644
--- a/src/repository.rs
+++ b/src/repository.rs
@@ -5,6 +5,7 @@ use ini::ini;
use std::collections::HashMap;
use std::io::Write;
use std::path::PathBuf;
+use crate::object::{GitCommit, GitObject, GitObjectType};
pub struct GitRepository {
pub worktree: PathBuf,
@@ -70,4 +71,16 @@ impl GitRepository {
}
println!("Git repository initialized in {}", repo.worktree.display());
}
+
+ pub fn cat_file(&self, object_type: GitObjectType, sha: &str) {
+ match object_type {
+ GitObjectType::Commit => {
+ let path = self.gitdir.join(&sha[..2]).join(&sha[2..]);
+ let git_object = GitObject::from_file(path);
+ let git_commit = GitCommit::from_git_object(git_object);
+ println!("{}", git_commit);
+ }
+ _ => {}
+ }
+ }
} \ No newline at end of file