diff --git a/Cargo.lock b/Cargo.lock index a189fab4..3bc642a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -988,15 +988,14 @@ dependencies = [ [[package]] name = "git2" -version = "0.20.4" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b88256088d75a56f8ecfa070513a775dd9107f6530ef14919dac831af9cfe2b" +checksum = "ddddbf932745a6be37109b6112d3ee09696106f848449069d3a57bba937ab82e" dependencies = [ "bitflags", "libc", "libgit2-sys", "log", - "url", ] [[package]] diff --git a/crates/knope/Cargo.toml b/crates/knope/Cargo.toml index 01671b0c..00682b2b 100644 --- a/crates/knope/Cargo.toml +++ b/crates/knope/Cargo.toml @@ -30,7 +30,7 @@ deno_path_util = "0.6.1" deno_semver = { workspace = true } dirs = "6.0.0" execute = "0.2.13" -git2 = { version = "0.20.0", default-features = false } +git2 = { version = "0.21.0", default-features = false } glob = "0.3.1" indexmap = { workspace = true } inquire = { version = "0.9.0", default-features = false, features = [ diff --git a/crates/knope/src/integrations/git.rs b/crates/knope/src/integrations/git.rs index 4bcd0edd..7d38bf86 100644 --- a/crates/knope/src/integrations/git.rs +++ b/crates/knope/src/integrations/git.rs @@ -180,7 +180,10 @@ pub(crate) fn select_issue_from_current_branch( pub(crate) fn current_branch() -> Result { let repo = Repository::open(".").map_err(ErrorKind::OpenRepo)?; let head = repo.head()?; - let ref_name = head.name().ok_or(ErrorKind::NotOnAGitBranch)?; + if !head.is_branch() { + return Err(ErrorKind::NotOnAGitBranch.into()); + } + let ref_name = head.name()?; Ok(ref_name.to_owned()) } @@ -188,10 +191,10 @@ pub(crate) fn current_branch() -> Result { pub(crate) fn get_first_remote() -> Option { let repo = Repository::open(".").ok()?; let remotes = repo.remotes().ok()?; - let remote_name = remotes.get(0)?; + let remote_name = remotes.get(0).ok()??; repo.find_remote(remote_name) .ok() - .and_then(|remote| remote.url().map(String::from)) + .and_then(|remote| remote.url().ok().map(String::from)) } fn select_issue_from_branch_name(ref_name: &str) -> Result { @@ -304,7 +307,7 @@ fn switch_to_branch(repo: &Repository, branch: &Branch) -> Result<(), Error> { let ref_name = branch .get() .name() - .ok_or(Error::from(ErrorKind::BadGitBranchName))?; + .map_err(|_| Error::from(ErrorKind::BadGitBranchName))?; repo.set_head(ref_name)?; repo.checkout_head(Some(CheckoutBuilder::new().force())) .map_err(ErrorKind::IncompleteCheckout)?; @@ -406,7 +409,7 @@ pub(crate) fn get_commit_messages_after_tag(tag: Option<&str>) -> Result) -> Result Option { Some(GitInfo { - author_name: commit.author().name().map(String::from)?, + author_name: commit.author().name().ok().map(String::from)?, hash: commit.id().to_string().get(..7).map(String::from)?, pr_number: None, pr_author_login: None, @@ -465,7 +468,7 @@ pub(crate) fn all_tags_on_branch() -> Result, Error> { let repo = Repository::open(current_dir().map_err(ErrorKind::CurrentDirectory)?)?; let mut all_tags: HashMap> = HashMap::new(); for reference in repo.references()?.filter_map(Result::ok) { - let Some(name) = reference.name() else { + let Ok(name) = reference.name() else { continue; }; if !name.starts_with("refs/tags/") {