3 Commits

Author SHA1 Message Date
5f98061581 Do not panic on empty remotes array 2021-11-20 17:49:22 +01:00
c97adefeb4 Add clippy fixes 2021-11-20 11:30:55 +01:00
34662ff728 README: Add link to creates.io 2021-11-20 11:29:57 +01:00
2 changed files with 36 additions and 40 deletions

View File

@@ -127,3 +127,7 @@ It requires nightly features due to the usage of [`std::path::Path::is_symlink()
* [`serde`](https://docs.rs/serde/) because we're using Rust, after all
* [`git2`](https://docs.rs/git2/), a safe wrapper around `libgit2`, for all git operations
* [`clap`](https://docs.rs/clap/), [`console`](https://docs.rs/console/) and [`shellexpand`](https://docs.rs/shellexpand) for good UX
# Links
* [crates.io](https://crates.io/crates/git-repo-manager)

View File

@@ -74,8 +74,7 @@ fn sync_trees(config: Config) {
process::exit(1);
}));
} else {
match &repo.remotes {
None => {
if matches!(&repo.remotes, None) || repo.remotes.as_ref().unwrap().len().clone() == 0 {
print_repo_action(
&repo.name,
"Repository does not have remotes configured, initializing new",
@@ -93,14 +92,8 @@ fn sync_trees(config: Config) {
None
}
}
}
Some(r) => {
let first = match r.first() {
Some(e) => e,
None => {
panic!("Repos is an empty array. This is a bug");
}
};
} else {
let first = repo.remotes.as_ref().unwrap().first().unwrap();
match clone_repo(first, &repo_path) {
Ok(_) => {
@@ -116,7 +109,6 @@ fn sync_trees(config: Config) {
};
}
}
}
if let Some(remotes) = &repo.remotes {
let repo_handle = repo_handle
.unwrap_or_else(|| open_repo(&repo_path).unwrap_or_else(|_| process::exit(1)));
@@ -376,7 +368,7 @@ fn add_table_header(table: &mut Table) {
]);
}
fn add_repo_status(table: &mut Table, repo_name: &String, repo_handle: &git2::Repository) {
fn add_repo_status(table: &mut Table, repo_name: &str, repo_handle: &git2::Repository) {
let repo_status = get_repo_status(repo_handle);
table.add_row(vec![
@@ -424,7 +416,7 @@ fn add_repo_status(table: &mut Table, repo_name: &String, repo_handle: &git2::Re
]);
}
fn show_single_repo_status(path: &PathBuf) {
fn show_single_repo_status(path: &Path) {
let mut table = Table::new();
add_table_header(&mut table);