Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
23 changes: 15 additions & 8 deletions src/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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))?;
Expand All @@ -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() {
Expand All @@ -234,7 +236,12 @@ pub fn update_existing(path: &Path) -> Result<()> {
pub fn get_remote_url(path: &Path) -> Result<Option<String>> {
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"),
}
Expand All @@ -253,7 +260,7 @@ fn current_branch_name(repository: &Repository) -> Result<String> {
.head()
.context("Failed to get HEAD")?
.shorthand()
.ok_or_else(|| anyhow!("Cannot determine branch name"))
.context("Cannot determine branch name")
.map(str::to_string)
}

Expand Down
2 changes: 1 addition & 1 deletion src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn get_remote_default_branch(url: &str) -> Result<String> {

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
Expand Down
Loading