diff --git a/Cargo.lock b/Cargo.lock index 5fa8dc0..1e6170e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -255,9 +255,9 @@ 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", @@ -445,9 +445,9 @@ checksum = "52ff2c0fe9bc6cb6b14a0592c2ff4fa9ceb83eea9db979b0487cd054946a2b8f" [[package]] name = "libgit2-sys" -version = "0.18.3+1.9.2" +version = "0.18.4+1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9b3acc4b91781bb0b3386669d325163746af5f6e4f73e6d2d630e09a35f3487" +checksum = "9b26f66f35e1871b22efcf7191564123d2a446ca0538cde63c23adfefa9b15b7" dependencies = [ "cc", "libc", @@ -1088,9 +1088,9 @@ dependencies = [ [[package]] name = "zerofrom" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69faa1f2a1ea75661980b013019ed6687ed0e83d069bc1114e2cc74c6c04c4df" +checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272" dependencies = [ "zerofrom-derive", ] diff --git a/Cargo.toml b/Cargo.toml index 8ec8ef8..497c39c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,12 +25,12 @@ tempfile = "3.27" shellexpand = "3.1" # Use system libgit2/OpenSSL by default so Linux `cargo install` does not # depend on vendored OpenSSL source builds and local Perl module availability. -git2 = "0.20.4" +git2 = { version = "0.21.0", features = ["https", "ssh"] } [target.'cfg(target_os = "macos")'.dependencies] # Keep vendored libgit2/OpenSSL on macOS to preserve the Darwin build stability # we needed for release packaging and git transport behavior. -git2 = { version = "0.20.4", features = ["vendored-libgit2", "vendored-openssl"] } +git2 = { version = "0.21.0", features = ["vendored-libgit2", "vendored-openssl", "https", "ssh"] } [dev-dependencies] tempfile = "3.27" diff --git a/src/clone.rs b/src/clone.rs index 6246d91..61c3953 100644 --- a/src/clone.rs +++ b/src/clone.rs @@ -140,8 +140,8 @@ pub fn has_unpushed_changes(path: &Path) -> bool { }; let branch_name = match head.shorthand() { - Some(name) => name, - None => return false, + Ok(name) => name, + Err(_) => return false, }; let local_branch = match repository.find_branch(branch_name, git2::BranchType::Local) { @@ -195,7 +195,11 @@ pub fn update_existing(path: &Path) -> Result<()> { let remotes = repository.remotes().context("Failed to get remotes")?; - for remote_name in remotes.iter().flatten() { + for remote_name in remotes.iter() { + let remote_name = match remote_name { + Ok(Some(name)) => name, + _ => continue, + }; let mut remote = repository .find_remote(remote_name) .with_context(|| format!("Failed to find remote '{}'", remote_name))?; @@ -208,9 +212,7 @@ pub fn update_existing(path: &Path) -> Result<()> { let head = repository.head().context("Failed to get HEAD")?; - let branch_name = head - .shorthand() - .ok_or_else(|| anyhow!("Cannot determine branch name"))?; + let branch_name = head.shorthand().context("Cannot determine branch name")?; if let Ok(local_branch) = repository.find_branch(branch_name, git2::BranchType::Local) { if let Ok(upstream_branch) = local_branch.upstream() { @@ -234,7 +236,12 @@ pub fn update_existing(path: &Path) -> Result<()> { pub fn get_remote_url(path: &Path) -> Result> { let repository = Repository::open(path).context("Failed to open repository")?; match repository.find_remote("origin") { - Ok(remote) => Ok(remote.url().map(|url_string| url_string.to_string())), + Ok(remote) => Ok(Some( + remote + .url() + .context("Failed to get remote URL")? + .to_string(), + )), Err(e) if e.code() == git2::ErrorCode::NotFound => Ok(None), Err(e) => Err(e).context("Failed to find origin remote"), } @@ -253,7 +260,7 @@ fn current_branch_name(repository: &Repository) -> Result { .head() .context("Failed to get HEAD")? .shorthand() - .ok_or_else(|| anyhow!("Cannot determine branch name")) + .context("Cannot determine branch name") .map(str::to_string) } diff --git a/src/git.rs b/src/git.rs index fb5d404..87864b6 100644 --- a/src/git.rs +++ b/src/git.rs @@ -43,7 +43,7 @@ pub fn get_remote_default_branch(url: &str) -> Result { let mut fetch_options = build_fetch_options(); - let remote_name = remote.name().unwrap_or("origin"); + let remote_name = remote.name()?.unwrap_or("origin"); let refspec = format!("+refs/heads/*:refs/remotes/{}/*", remote_name); remote