mirror of
https://github.com/msfjarvis/gitice
synced 2025-08-14 11:47:01 +05:30
Start wiring up real data
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
59bf51b37f
commit
5fcba2926c
1 changed files with 20 additions and 7 deletions
27
src/main.rs
27
src/main.rs
|
@ -1,7 +1,15 @@
|
|||
use git2::Repository;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::Path;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct PersistableRepo {
|
||||
pub(crate) path: String,
|
||||
pub(crate) remote_url: String,
|
||||
pub(crate) head: String,
|
||||
}
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let dir = match std::env::args().nth(1) {
|
||||
Some(d) => d,
|
||||
|
@ -10,7 +18,7 @@ fn main() -> anyhow::Result<()> {
|
|||
return Ok(());
|
||||
}
|
||||
};
|
||||
let mut items: Vec<String> = Vec::new();
|
||||
let mut repos: Vec<PersistableRepo> = Vec::new();
|
||||
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());
|
||||
|
@ -21,14 +29,19 @@ fn main() -> anyhow::Result<()> {
|
|||
continue;
|
||||
}
|
||||
|
||||
items.push(format!(
|
||||
"{} = {}",
|
||||
entry.path().to_string_lossy().to_string(),
|
||||
repo.head()?.name().unwrap_or("None")
|
||||
));
|
||||
let head = repo.head()?;
|
||||
if let Some(head) = head.name() {
|
||||
repos.push(PersistableRepo {
|
||||
// Ideally we wanna do this, but it moves `dir`.
|
||||
// path: entry.path().to_string_lossy().strip_prefix(dir).unwrap().to_string(),
|
||||
path: entry.path().to_string_lossy().to_string(),
|
||||
remote_url: repo.remotes()?.get(0).unwrap_or("None").to_string(),
|
||||
head: head.to_string(),
|
||||
});
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
println!("{:#x?}", items);
|
||||
println!("{:#x?}", repos);
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue