fix: dont panic if git initialized without any remote

This commit is contained in:
Jozef Steinhübl 2024-07-24 07:04:04 +02:00
parent ab6fd3481d
commit bc8fea3e78
No known key found for this signature in database
GPG key ID: E6BC90C91973B08F

View file

@ -32,11 +32,12 @@ fn get_main_remote_url(repository: Repository) -> Option<String> {
}
return match repository.remotes() {
Ok(remotes) => repository
.find_remote(remotes.get(0).unwrap())
.unwrap()
.url()
.map(|url| transform_url(url.to_string())),
Ok(remotes) => remotes.get(0).and_then(|name| {
repository
.find_remote(name)
.ok()
.and_then(|remote| remote.url().map(|url| transform_url(url.to_string())))
}),
Err(_) => None,
};
}