use std::path::PathBuf;
use git2::{Repository, TreeWalkMode};
pub fn get_bare_repository_files(path: PathBuf) -> Vec<PathBuf> {
if let Ok(repo) = Repository::open_bare(path) {
if let Ok(current_tree) = repo.head().map(|head| head.peel_to_tree()) {
let mut files: Vec<PathBuf> = Vec::new();
match current_tree {
Ok(tree) => {
tree.walk(TreeWalkMode::PreOrder, |root, entry| {
if entry
.kind()
.map_or(false, |kind| kind.eq(&git2::ObjectType::Blob))
{
files.push(PathBuf::from(format!(
"{}{}",
root,
entry.name().expect("Error getting file name")
)));
}
git2::TreeWalkResult::Ok
})
.expect("Error walking through tree");
}
Err(e) => {
println!("{:?}", e);
}
};
files
} else {
println!("Error retrieving tree");
Vec::new()
}
} else {
println!("Could not open repository");
Vec::new()
}
}