From bc8fea3e784fcda75ffc10fc7aab648e9aeeca92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Wed, 24 Jul 2024 07:04:04 +0200 Subject: [PATCH] fix: dont panic if git initialized without any remote --- lsp/src/git.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lsp/src/git.rs b/lsp/src/git.rs index eeddb67..cd5b216 100644 --- a/lsp/src/git.rs +++ b/lsp/src/git.rs @@ -32,11 +32,12 @@ fn get_main_remote_url(repository: Repository) -> Option { } 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, }; }