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
5 changes: 2 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ flate2 = { version = "1.0.25", default-features = false, features = [
"rust_backend",
] }
futures-util = "0.3"
git2 = { version = "0.20.4", default-features = false }
git2 = { version = "0.21.0", default-features = false }
glob = "0.3.1"
http = "1.4.0"
if_chain = "1.0.2"
Expand Down
14 changes: 9 additions & 5 deletions src/commands/code_mappings/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,15 @@ fn resolve_git_remote(repo: &git2::Repository) -> Option<String> {
/// Finds the remote whose URL matches the given repository name (e.g. "owner/repo").
fn find_remote_for_repo(repo: &git2::Repository, repo_name: &str) -> Option<String> {
let remotes = repo.remotes().ok()?;
let found = remotes.iter().flatten().find(|name| {
vcs::git_repo_remote_url(repo, name)
.map(|url| vcs::get_repo_from_remote_preserve_case(&url) == repo_name)
.unwrap_or(false)
})?;
let found = remotes
.iter()
.filter_map(Result::ok)
.flatten()
.find(|name| {
vcs::git_repo_remote_url(repo, name)
.map(|url| vcs::get_repo_from_remote_preserve_case(&url) == repo_name)
.unwrap_or(false)
})?;
debug!("Found remote '{found}' matching repo '{repo_name}'");
Some(found.to_owned())
}
Expand Down
23 changes: 10 additions & 13 deletions src/utils/vcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,7 @@ pub fn git_repo_remote_url(
cached_remote: &str,
) -> Result<String, git2::Error> {
let remote = repo.find_remote(cached_remote)?;
remote
.url()
.map(|url| url.to_owned())
.ok_or_else(|| git2::Error::from_str("No remote URL found"))
remote.url().map(|url| url.to_owned())
}

pub fn git_repo_head_ref(repo: &git2::Repository) -> Result<String> {
Expand All @@ -269,7 +266,7 @@ pub fn git_repo_head_ref(repo: &git2::Repository) -> Result<String> {
if head.is_branch() {
head.shorthand()
.map(|s| s.to_owned())
.ok_or_else(|| anyhow::anyhow!("No HEAD reference found"))
.with_context(|| "No HEAD reference found")
} else {
// In detached HEAD state, return an error to indicate no valid branch reference
Err(anyhow::anyhow!(
Expand All @@ -287,7 +284,7 @@ pub fn git_repo_base_ref(repo: &git2::Repository, remote_name: &str) -> Result<S
let name = remote_ref
.resolve()?
.shorthand()
.ok_or(anyhow::anyhow!("Remote branch name is not valid UTF-8"))?
.with_context(|| "Remote branch name is not valid UTF-8")?
.to_owned();

let expected_prefix = format!("{remote_name}/");
Expand All @@ -305,7 +302,7 @@ pub fn git_repo_base_ref(repo: &git2::Repository, remote_name: &str) -> Result<S
/// Prefers "upstream" if it exists, then "origin", otherwise uses the first remote.
pub fn find_best_remote(repo: &git2::Repository) -> Result<Option<String>> {
let remotes = repo.remotes()?;
let remote_names: Vec<&str> = remotes.iter().flatten().collect();
let remote_names: Vec<&str> = remotes.iter().filter_map(Result::ok).flatten().collect();

if remote_names.is_empty() {
return Ok(None);
Expand Down Expand Up @@ -469,7 +466,7 @@ fn find_matching_rev(
// mode we want to also check for matching URLs.
if_chain! {
if let Ok(remote) = repo.find_remote(&remote_name.unwrap_or_else(|| "origin".to_owned()));
if let Some(url) = remote.url();
if let Ok(url) = remote.url();
then {
if !discovery || is_matching_url(url, &reference_url) {
debug!(" found match: {url} == {}, {r:?}", &reference_url);
Expand Down Expand Up @@ -501,7 +498,7 @@ fn find_matching_submodule(
) -> Result<Option<String>> {
// in discovery mode we want to find that repo in associated submodules.
for submodule in repo.submodules()? {
if let Some(submodule_url) = submodule.url() {
if let Ok(Some(submodule_url)) = submodule.url() {
debug!(" found submodule with URL {submodule_url}");
if is_matching_url(submodule_url, &reference_url) {
debug!(
Expand Down Expand Up @@ -792,9 +789,9 @@ pub fn generate_patch_set(
for (index, commit) in commits.iter().enumerate() {
let mut git_commit = GitCommit {
id: commit.id().to_string(),
author_name: commit.author().name().map(|s| s.to_owned()),
author_email: commit.author().email().map(|s| s.to_owned()),
message: commit.message().map(|s| s.to_owned()),
author_name: commit.author().name().ok().map(|s| s.to_owned()),
author_email: commit.author().email().ok().map(|s| s.to_owned()),
message: commit.message().ok().map(|s| s.to_owned()),
repository: repository.to_owned(),
timestamp: get_commit_time(commit.author().when()),
patch_set: vec![],
Expand Down Expand Up @@ -1375,7 +1372,7 @@ mod tests {
(
c.author().name().unwrap().to_owned(),
c.author().email().unwrap().to_owned(),
c.summary(),
c.summary().unwrap(),
)
})
.collect::<Vec<_>>());
Expand Down
Loading