Merge pull request #11 from nonnominandus/master

Made a single error message not stall the repo finding process
This commit is contained in:
2021-11-30 09:50:04 +01:00
committed by GitHub

View File

@@ -363,8 +363,7 @@ fn find_repos(root: &Path) -> Option<(Vec<Repo>, bool)> {
if path == root { if path == root {
repo_in_root = true; repo_in_root = true;
} }
let repo = match open_repo(&path, is_worktree) { match open_repo(&path, is_worktree) {
Ok(r) => r,
Err(e) => { Err(e) => {
print_error(&format!( print_error(&format!(
"Error opening repo {}{}: {}", "Error opening repo {}{}: {}",
@@ -375,92 +374,93 @@ fn find_repos(root: &Path) -> Option<(Vec<Repo>, bool)> {
}, },
e e
)); ));
return None;
} }
}; Ok(repo) => {
let remotes = match repo.remotes() {
let remotes = match repo.remotes() { Ok(remotes) => {
Ok(remotes) => { let mut results: Vec<Remote> = Vec::new();
let mut results: Vec<Remote> = Vec::new(); for remote in remotes.iter() {
for remote in remotes.iter() { match remote {
match remote { Some(remote_name) => {
Some(remote_name) => { match repo.find_remote(remote_name) {
match repo.find_remote(remote_name) { Ok(remote) => {
Ok(remote) => { let name = match remote.name() {
let name = match remote.name() { Some(name) => name.to_string(),
Some(name) => name.to_string(), None => {
None => { print_repo_error(&path_as_string(&path), &format!("Falied getting name of remote \"{}\". This is most likely caused by a non-utf8 remote name", remote_name));
print_repo_error(&path_as_string(&path), &format!("Falied getting name of remote \"{}\". This is most likely caused by a non-utf8 remote name", remote_name)); process::exit(1);
process::exit(1); }
};
let url = match remote.url() {
Some(url) => url.to_string(),
None => {
print_repo_error(&path_as_string(&path), &format!("Falied getting URL of remote \"{}\". This is most likely caused by a non-utf8 URL", name));
process::exit(1);
}
};
let remote_type = match detect_remote_type(&url) {
Some(t) => t,
None => {
print_repo_error(
&path_as_string(&path),
&format!(
"Could not detect remote type of \"{}\"",
&url
),
);
process::exit(1);
}
};
results.push(Remote {
name,
url,
remote_type,
});
} }
}; Err(e) => {
let url = match remote.url() {
Some(url) => url.to_string(),
None => {
print_repo_error(&path_as_string(&path), &format!("Falied getting URL of remote \"{}\". This is most likely caused by a non-utf8 URL", name));
process::exit(1);
}
};
let remote_type = match detect_remote_type(&url) {
Some(t) => t,
None => {
print_repo_error( print_repo_error(
&path_as_string(&path), &path_as_string(&path),
&format!( &format!(
"Could not detect remote type of \"{}\"", "Error getting remote {}: {}",
&url remote_name, e
), ),
); );
process::exit(1); process::exit(1);
} }
}; };
results.push(Remote {
name,
url,
remote_type,
});
} }
Err(e) => { None => {
print_repo_error( print_repo_error(&path_as_string(&path), "Error getting remote. This is most likely caused by a non-utf8 remote name");
&path_as_string(&path),
&format!("Error getting remote {}: {}", remote_name, e),
);
process::exit(1); process::exit(1);
} }
}; };
} }
None => { Some(results)
print_repo_error(&path_as_string(&path), "Error getting remote. This is most likely caused by a non-utf8 remote name"); }
process::exit(1); Err(e) => {
print_repo_error(
&path_as_string(&path),
&format!("Error getting remotes: {}", e),
);
process::exit(1);
}
};
repos.push(Repo {
name: match path == root {
true => match &root.parent() {
Some(parent) => path_as_string(path.strip_prefix(parent).unwrap()),
None => {
print_error("Getting name of the search root failed. Do you have a git repository in \"/\"?");
process::exit(1);
},
} }
}; false => path_as_string(path.strip_prefix(&root).unwrap()),
} },
Some(results) remotes,
} worktree_setup: is_worktree,
Err(e) => { });
print_repo_error(
&path_as_string(&path),
&format!("Error getting remotes: {}", e),
);
process::exit(1);
} }
}; };
repos.push(Repo {
name: match path == root {
true => match &root.parent() {
Some(parent) => path_as_string(path.strip_prefix(parent).unwrap()),
None => {
print_error("Getting name of the search root failed. Do you have a git repository in \"/\"?");
process::exit(1);
},
}
false => path_as_string(path.strip_prefix(&root).unwrap()),
},
remotes,
worktree_setup: is_worktree,
});
} }
Some((repos, repo_in_root)) Some((repos, repo_in_root))
} }