diff --git a/src/main.rs b/src/main.rs
index 4ff7029..5f68f4b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,4 @@
+use git2::Repository;
use std::path::Path;
use walkdir::WalkDir;
@@ -7,18 +8,33 @@ fn main() {
None => {
println!("Usage:\n gitice
\n");
return;
- },
+ }
};
let mut items: Vec = Vec::new();
- for entry in WalkDir::new(dir)
- .into_iter()
- .filter_map(|e| e.ok())
- {
+ for entry in WalkDir::new(dir).into_iter().filter_map(|e| e.ok()) {
if entry.file_type().is_dir() {
let path = format!("{}/.git", entry.path().display());
let git_dir = Path::new(&path);
if git_dir.exists() {
- items.push(entry.path().to_string_lossy().to_string());
+ let repo = match Repository::open(git_dir) {
+ Ok(repo) => repo,
+ Err(e) => {
+ println!("Failed to open repository: {}", e);
+ return;
+ }
+ };
+ let head = match repo.head() {
+ Ok(head) => head,
+ Err(e) => {
+ println!("Failed getting repository head: {}", e);
+ return;
+ }
+ };
+ items.push(format!(
+ "{} = {}",
+ entry.path().to_string_lossy().to_string(),
+ head.name().unwrap()
+ ));
}
};
}