From 444dea3e036fea14892040023bada4d9e0d7b9f6 Mon Sep 17 00:00:00 2001 From: ATechnoHazard Date: Mon, 19 Oct 2020 03:02:08 +0530 Subject: [PATCH] Strip dir path prefix without moving Signed-off-by: ATechnoHazard --- src/main.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 822c9a3..e7596a4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,7 @@ fn main() -> anyhow::Result<()> { }; let mut repos: HashMap = HashMap::new(); - for entry in WalkDir::new(dir).into_iter().filter_map(|e| e.ok()) { + for entry in WalkDir::new(dir.clone()).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); @@ -39,12 +39,15 @@ fn main() -> anyhow::Result<()> { // doesn't seem to work with the full name such as `refs/remotes/origin/master` upstream.as_str().unwrap().split('/').collect::>()[2], ) { - let path = entry.path().to_string_lossy().to_string(); + let path = entry + .path() + .to_string_lossy() + .strip_prefix(&dir) + .unwrap() + .to_string(); repos.insert( path.clone(), PersistableRepo { - // Ideally we wanna do this, but it moves `dir`. - // path: entry.path().to_string_lossy().strip_prefix(dir).unwrap().to_string(), path, remote_url: remote.url().unwrap_or("None").to_owned(), head: head.to_owned(),