mirror of
https://github.com/msfjarvis/gitice
synced 2025-08-14 10:37:01 +05:30
Test reading git repo metadata
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
820fc6f1ab
commit
9da03c9207
1 changed files with 22 additions and 6 deletions
28
src/main.rs
28
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 <dir>\n");
|
||||
return;
|
||||
},
|
||||
}
|
||||
};
|
||||
let mut items: Vec<String> = 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()
|
||||
));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue