Skip to content
Draft
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
32 changes: 4 additions & 28 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 asyncgit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ crossbeam-channel = "0.5"
dirs = "6.0"
easy-cast = "0.5"
fuzzy-matcher = "0.3"
git2 = "0.20"
git2 = { version = "0.21", features = ["cred"] }
git2-hooks = { path = "../git2-hooks", version = "0.7" }
gix = { version = "0.78.0", default-features = false, features = [
"mailmap",
Expand Down
6 changes: 4 additions & 2 deletions asyncgit/src/sync/branch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ pub fn get_branches_info(
.branch_upstream_remote(&reference)
.ok()
.as_ref()
.and_then(git2::Buf::as_str)
.and_then(|upstream_remote| {
git2::Buf::as_str(upstream_remote).ok()
})
.map(String::from);

let name_bytes = branch.name_bytes()?;
Expand Down Expand Up @@ -332,7 +334,7 @@ pub fn checkout_branch(
Some(&mut git2::build::CheckoutBuilder::new()),
)?;

let branch_ref = branch_ref.name().ok_or_else(|| {
let branch_ref = branch_ref.name().map_err(|_| {
Error::Generic(String::from("branch ref not found"))
});

Expand Down
2 changes: 1 addition & 1 deletion asyncgit/src/sync/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub(crate) fn signature_allow_undefined_name(
config.get_entry("user.name"),
config.get_entry("user.email"),
) {
if let Some(email) = email_entry.value() {
if let Ok(email) = email_entry.value() {
return Signature::now("unknown", email);
}
};
Expand Down
18 changes: 13 additions & 5 deletions asyncgit/src/sync/commit_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ pub fn filter_commit_by_search(
.fields
.contains(SearchFields::MESSAGE_SUMMARY)
.then(|| {
commit.summary().map(|msg| filter.match_text(msg))
commit
.summary()
.ok()
.flatten()
.map(|msg| filter.match_text(msg))
})
.flatten()
.unwrap_or_default();
Expand All @@ -180,7 +184,11 @@ pub fn filter_commit_by_search(
.fields
.contains(SearchFields::MESSAGE_BODY)
.then(|| {
commit.body().map(|msg| filter.match_text(msg))
commit
.body()
.ok()
.flatten()
.map(|msg| filter.match_text(msg))
})
.flatten()
.unwrap_or_default();
Expand All @@ -206,9 +214,9 @@ pub fn filter_commit_by_search(
let author = get_author_of_commit(&commit, &mailmap);
[author.email(), author.name()].iter().any(
|opt_haystack| {
opt_haystack.is_some_and(|haystack| {
filter.match_text(haystack)
})
opt_haystack.as_ref().ok().is_some_and(
|haystack| filter.match_text(haystack),
)
},
)
} else {
Expand Down
3 changes: 2 additions & 1 deletion asyncgit/src/sync/commits_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct CommitId(Oid);

impl Default for CommitId {
fn default() -> Self {
Self(Oid::zero())
Self(Oid::ZERO_SHA1)
}
}

Expand Down Expand Up @@ -146,6 +146,7 @@ pub fn get_commits_info(
let message = get_message(&c, Some(message_length_limit));
let author = get_author_of_commit(&c, &mailmap)
.name()
.ok()
.map_or_else(
|| String::from("<unknown>"),
String::from,
Expand Down
2 changes: 1 addition & 1 deletion asyncgit/src/sync/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub fn get_config_string_repo(
};

if entry.has_value() {
Ok(entry.value().map(std::string::ToString::to_string))
Ok(entry.value().ok().map(std::string::ToString::to_string))
} else {
Ok(None)
}
Expand Down
18 changes: 11 additions & 7 deletions asyncgit/src/sync/cred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ pub fn need_username_password(repo_path: &RepoPath) -> Result<bool> {
repo.find_remote(&get_default_remote_in_repo(&repo)?)?;
let url = remote
.pushurl()
.or_else(|| remote.url())
.ok()
.flatten()
.or_else(|| remote.url().ok())
.ok_or(Error::UnknownRemote)?
.to_owned();
let is_http = url.starts_with("http");
Expand All @@ -58,11 +60,8 @@ pub fn need_username_password_for_fetch(
let repo = repo(repo_path)?;
let remote = repo
.find_remote(&get_default_remote_for_fetch_in_repo(&repo)?)?;
let url = remote
.url()
.or_else(|| remote.url())
.ok_or(Error::UnknownRemote)?
.to_owned();
let url =
remote.url().map_err(|_| Error::UnknownRemote)?.to_owned();
let is_http = url.starts_with("http");
Ok(is_http)
}
Expand All @@ -78,7 +77,9 @@ pub fn need_username_password_for_push(
.find_remote(&get_default_remote_for_push_in_repo(&repo)?)?;
let url = remote
.pushurl()
.or_else(|| remote.url())
.ok()
.flatten()
.or_else(|| remote.url().ok())
.ok_or(Error::UnknownRemote)?
.to_owned();
let is_http = url.starts_with("http");
Expand All @@ -93,6 +94,7 @@ pub fn extract_username_password(
let url = repo
.find_remote(&get_default_remote_in_repo(&repo)?)?
.url()
.ok()
.ok_or(Error::UnknownRemote)?
.to_owned();
let mut helper = CredentialHelper::new(&url);
Expand Down Expand Up @@ -122,6 +124,7 @@ pub fn extract_username_password_for_fetch(
let url = repo
.find_remote(&get_default_remote_for_fetch_in_repo(&repo)?)?
.url()
.ok()
.ok_or(Error::UnknownRemote)?
.to_owned();
let mut helper = CredentialHelper::new(&url);
Expand Down Expand Up @@ -151,6 +154,7 @@ pub fn extract_username_password_for_push(
let url = repo
.find_remote(&get_default_remote_for_push_in_repo(&repo)?)?
.url()
.ok()
.ok_or(Error::UnknownRemote)?
.to_owned();
let mut helper = CredentialHelper::new(&url);
Expand Down
4 changes: 3 additions & 1 deletion asyncgit/src/sync/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ pub fn hooks_pre_push(
let git_remote = repo.find_remote(remote)?;
let url = git_remote
.pushurl()
.or_else(|| git_remote.url())
.ok()
.flatten()
.or_else(|| git_remote.url().ok())
.ok_or_else(|| {
crate::error::Error::Generic(format!(
"remote '{remote}' has no URL configured"
Expand Down
20 changes: 13 additions & 7 deletions asyncgit/src/sync/remotes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@ pub fn get_remotes(repo_path: &RepoPath) -> Result<Vec<String>> {

let repo = repo(repo_path)?;
let remotes = repo.remotes()?;
let remotes: Vec<String> =
remotes.iter().flatten().map(String::from).collect();
let remotes: Vec<String> = remotes
.iter()
.flatten()
.flatten()
.map(String::from)
.collect();

Ok(remotes)
}
Expand All @@ -102,7 +106,7 @@ pub fn get_remote_url(
let repo = repo(repo_path)?;
let remote = repo.find_remote(remote_name)?.clone();
let url = remote.url();
if let Some(u) = url {
if let Ok(u) = url {
return Ok(Some(u.to_string()));
}
Ok(None)
Expand Down Expand Up @@ -241,9 +245,9 @@ pub(crate) fn get_default_remote_in_repo(
let remotes = repo.remotes()?;

// if `origin` exists return that
let found_origin = remotes
.iter()
.any(|r| r.is_some_and(|r| r == DEFAULT_REMOTE_NAME));
let found_origin = remotes.iter().any(|r| {
r.ok().flatten().is_some_and(|r| r == DEFAULT_REMOTE_NAME)
});
if found_origin {
return Ok(DEFAULT_REMOTE_NAME.into());
}
Expand All @@ -252,8 +256,9 @@ pub(crate) fn get_default_remote_in_repo(
if remotes.len() == 1 {
let first_remote = remotes
.iter()
.next()
.flatten()
.flatten()
.next()
.map(String::from)
.ok_or_else(|| {
Error::Generic("no remote found".into())
Expand Down Expand Up @@ -307,6 +312,7 @@ pub fn fetch_all(
.remotes()?
.iter()
.flatten()
.flatten()
.map(String::from)
.collect::<Vec<_>>();
let remotes_count = remotes.len();
Expand Down
4 changes: 3 additions & 1 deletion asyncgit/src/sync/remotes/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ pub fn tags_missing_remote(

let mut local_tags = tags
.iter()
.filter_map(|tag| tag.map(|tag| format!("refs/tags/{tag}")))
.filter_map(|tag| {
tag.ok().flatten().map(|tag| format!("refs/tags/{tag}"))
})
.collect::<HashSet<_>>();
let remote_tags =
remote_tag_refs(repo_path, remote, basic_credential)?;
Expand Down
2 changes: 1 addition & 1 deletion asyncgit/src/sync/submodules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn submodule_to_info(s: &Submodule, r: &Repository) -> SubmoduleInfo {
path: s.path().to_path_buf(),
id: s.workdir_id().map(CommitId::from),
head_id: s.head_id().map(CommitId::from),
url: s.url().map(String::from),
url: s.url().ok().flatten().map(String::from),
status,
}
}
Expand Down
6 changes: 3 additions & 3 deletions asyncgit/src/sync/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ mod tests {
.map(|f| TreeFile {
path: PathBuf::from(f),
filemode: 0,
id: Oid::zero(),
id: Oid::ZERO_SHA1,
})
.collect::<Vec<_>>();

Expand All @@ -186,7 +186,7 @@ mod tests {
.map(|f| TreeFile {
path: PathBuf::from(f),
filemode: 0,
id: Oid::zero(),
id: Oid::ZERO_SHA1,
})
.collect::<Vec<_>>();

Expand All @@ -210,7 +210,7 @@ mod tests {
.map(|f| TreeFile {
path: PathBuf::from(f),
filemode: 0,
id: Oid::zero(),
id: Oid::ZERO_SHA1,
})
.collect::<Vec<_>>();

Expand Down
2 changes: 1 addition & 1 deletion git2-hooks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ categories = ["development-tools"]
keywords = ["git"]

[dependencies]
git2 = ">=0.17"
git2 = "0.21"
gix-path = "0.11"
log = "0.4"
shellexpand = "3.1"
Expand Down
2 changes: 1 addition & 1 deletion git2-hooks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ exit 2
let res = hooks_prepare_commit_msg(
&repo,
None,
PrepareCommitMsgSource::Commit(git2::Oid::zero()),
PrepareCommitMsgSource::Commit(git2::Oid::ZERO_SHA1),
&mut msg,
)
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion git2-testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ keywords = ["git"]

[dependencies]
env_logger = "0.11"
git2 = ">=0.17"
git2 = "0.21"
log = "0.4"
tempfile = "3"
Loading