Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
radicle/git/raw: Introduce `trait ErrorExt`
✗ CI failure Lorenz Leutgeb committed 7 months ago
commit 4facd78316d892d27a926f11c274ef2f2cf6fbc9
parent bccd86099ad31f39e643a56bd7d4366721e7bed5
2 failed (2 total) View logs
10 files changed +33 -21
modified crates/radicle-cli/src/commands/init.rs
@@ -13,6 +13,7 @@ use serde_json as json;
use radicle::crypto::ssh;
use radicle::explorer::ExplorerUrl;
use radicle::git::raw;
+
use radicle::git::raw::ErrorExt as _;
use radicle::git::RefString;
use radicle::identity::project::ProjectName;
use radicle::identity::{Doc, RepoId, Visibility};
@@ -189,7 +190,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
    let path = options.path.as_deref().unwrap_or(cwd.as_path());
    let repo = match git::Repository::open(path) {
        Ok(r) => r,
-
        Err(e) if radicle::git::ext::is_not_found_err(&e) => {
+
        Err(e) if e.is_not_found() => {
            anyhow::bail!("a Git repository was not found at the given path")
        }
        Err(e) => return Err(e.into()),
modified crates/radicle-cli/src/commands/patch/checkout.rs
@@ -3,6 +3,7 @@ use anyhow::anyhow;
use git_ref_format::Qualified;
use radicle::cob::patch;
use radicle::cob::patch::RevisionId;
+
use radicle::git::raw::ErrorExt as _;
use radicle::git::RefString;
use radicle::patch::cache::Patches as _;
use radicle::patch::PatchId;
@@ -73,7 +74,7 @@ pub fn run(
                }
                head
            }
-
            Err(e) if radicle::git::is_not_found_err(&e) => {
+
            Err(e) if e.is_not_found() => {
                let commit = find_patch_commit(revision, stored, working)?;
                // Create patch branch and switch to it.
                working.branch(patch_branch.as_str(), &commit, true)?;
@@ -128,7 +129,7 @@ fn find_patch_commit<'a>(

    match working.find_commit(head) {
        Ok(commit) => Ok(commit),
-
        Err(e) if git::ext::is_not_found_err(&e) => {
+
        Err(e) if e.is_not_found() => {
            let output = git::process::fetch_pack(
                Some(working.path()),
                stored,
modified crates/radicle-cli/src/commands/watch.rs
@@ -4,6 +4,7 @@ use std::{thread, time};
use anyhow::{anyhow, Context as _};

use radicle::git;
+
use radicle::git::raw::ErrorExt as _;
use radicle::prelude::{NodeId, RepoId};
use radicle::storage::{ReadRepository, ReadStorage};

@@ -169,7 +170,7 @@ fn reference<R: ReadRepository>(
) -> Result<Option<git::Oid>, git::raw::Error> {
    match repo.reference_oid(nid, qual) {
        Ok(oid) => Ok(Some(oid)),
-
        Err(e) if git::ext::is_not_found_err(&e) => Ok(None),
+
        Err(e) if e.is_not_found() => Ok(None),
        Err(e) => Err(e),
    }
}
modified crates/radicle-fetch/src/git/repository.rs
@@ -53,7 +53,9 @@ fn find_and_peel(repo: &Repository, oid: Oid) -> Result<Oid, error::Ancestry> {
            .map_err(|err| error::Ancestry::Peel { oid, err })?
            .id()
            .into()),
-
        Err(e) if git::is_not_found_err(&e) => Err(error::Ancestry::Missing { oid }),
+
        Err(e) if e.code() == git::raw::ErrorCode::NotFound => {
+
            Err(error::Ancestry::Missing { oid })
+
        }
        Err(err) => Err(error::Ancestry::Object { oid, err }),
    }
}
modified crates/radicle/src/git.rs
@@ -17,7 +17,6 @@ use crate::storage;
use crate::storage::refs::Refs;
use crate::storage::RemoteId;

-
pub use ext::is_not_found_err;
pub use ext::Error;
pub use ext::NotFound;
pub use ext::Oid;
@@ -31,6 +30,8 @@ pub use radicle_git_ext as ext;
pub use storage::git::transport::local::Url;
pub use storage::BranchName;

+
use raw::ErrorExt as _;
+

/// Default port of the `git` transport protocol.
pub const PROTOCOL_PORT: u16 = 9418;
/// Minimum required git version.
@@ -733,14 +734,14 @@ pub fn set_upstream(
    let branch_merge = format!("branch.{branch}.merge");

    config.remove_multivar(&branch_remote, ".*").or_else(|e| {
-
        if ext::is_not_found_err(&e) {
+
        if e.is_not_found() {
            Ok(())
        } else {
            Err(e)
        }
    })?;
    config.remove_multivar(&branch_merge, ".*").or_else(|e| {
-
        if ext::is_not_found_err(&e) {
+
        if e.is_not_found() {
            Ok(())
        } else {
            Err(e)
modified crates/radicle/src/git/canonical/effects.rs
@@ -1,6 +1,7 @@
use std::collections::{BTreeMap, BTreeSet};

use crate::git;
+
use crate::git::raw::ErrorExt as _;
use crate::git::{Oid, Qualified};
use crate::prelude::Did;

@@ -215,7 +216,7 @@ impl FindObjects for git::raw::Repository {
            let name = &refname.with_namespace(did.as_key().into());
            let reference = match self.find_reference(name.as_str()) {
                Ok(reference) => reference,
-
                Err(e) if git::ext::is_not_found_err(&e) => {
+
                Err(e) if e.is_not_found() => {
                    missing_refs.insert(name.to_owned());
                    continue;
                }
@@ -235,7 +236,7 @@ impl FindObjects for git::raw::Repository {
                        object.kind().map(|kind| kind.to_string()),
                    )
                }),
-
                Err(err) if git::ext::is_not_found_err(&err) => {
+
                Err(err) if err.is_not_found() => {
                    missing_objects.insert(*did, oid);
                    continue;
                }
modified crates/radicle/src/identity/doc.rs
@@ -22,6 +22,7 @@ use crate::crypto;
use crate::crypto::Signature;
use crate::git;
use crate::git::canonical::rules;
+
use crate::git::raw::ErrorExt as _;
use crate::identity::{project::Project, Did};
use crate::node::device::Device;
use crate::storage;
@@ -71,9 +72,8 @@ impl DocError {
    /// Whether this error is caused by the document not being found.
    pub fn is_not_found(&self) -> bool {
        match self {
-
            Self::GitExt(git::Error::NotFound(_)) => true,
-
            Self::GitExt(git::Error::Git(e)) if git::is_not_found_err(e) => true,
-
            Self::Git(err) if git::is_not_found_err(err) => true,
+
            Self::GitExt(e) => e.is_not_found(),
+
            Self::Git(e) => e.is_not_found(),
            _ => false,
        }
    }
@@ -1160,7 +1160,10 @@ mod test {
        let oid = git::raw::Oid::from_str("2d52a53ce5e4f141148a5f770cfd3ead2d6a45b8").unwrap();

        let err = repo.identity_head_of(&remote).unwrap_err();
-
        matches!(err, git::ext::Error::NotFound(_));
+
        {
+
            use crate::git::raw::ErrorExt as _;
+
            assert!(err.is_not_found());
+
        }

        let err = Doc::load_at(oid.into(), &repo).unwrap_err();
        assert!(err.is_not_found());
modified crates/radicle/src/storage.rs
@@ -16,6 +16,7 @@ pub use radicle_git_ext::Oid;

use crate::cob;
use crate::collections::RandomMap;
+
use crate::git::raw::ErrorExt as _;
use crate::git::{canonical, ext as git_ext};
use crate::git::{refspec::Refspec, PatternString, Qualified, RefError, RefStr, RefString};
use crate::identity::{doc, Did, PayloadError};
@@ -134,8 +135,8 @@ impl RepositoryError {
    pub fn is_not_found(&self) -> bool {
        match self {
            Self::Storage(e) if e.is_not_found() => true,
-
            Self::Git(e) if git_ext::is_not_found_err(e) => true,
            Self::GitExt(git_ext::Error::NotFound(_)) => true,
+
            Self::Git(e) if e.is_not_found() => true,
            _ => false,
        }
    }
@@ -167,7 +168,7 @@ impl Error {
    pub fn is_not_found(&self) -> bool {
        match self {
            Self::Io(e) if e.kind() == io::ErrorKind::NotFound => true,
-
            Self::Git(e) if git::ext::is_not_found_err(e) => true,
+
            Self::Git(e) if e.is_not_found() => true,
            Self::Doc(e) if e.is_not_found() => true,
            _ => false,
        }
modified crates/radicle/src/storage/git.rs
@@ -14,6 +14,7 @@ use std::{fs, io};
use crypto::Verified;

use crate::git::canonical::Quorum;
+
use crate::git::raw::ErrorExt as _;
use crate::identity::crefs::GetCanonicalRefs as _;
use crate::identity::doc::DocError;
use crate::identity::{CanonicalRefs, Doc, DocAt, RepoId};
@@ -817,7 +818,7 @@ impl ReadRepository for Repository {

        match result {
            Ok(oid) => Ok(oid),
-
            Err(err) if git::ext::is_not_found_err(&err) => self.canonical_identity_head(),
+
            Err(err) if err.is_not_found() => self.canonical_identity_head(),
            Err(err) => Err(err.into()),
        }
    }
modified crates/radicle/src/storage/refs.rs
@@ -14,6 +14,7 @@ use thiserror::Error;

use crate::git;
use crate::git::ext as git_ext;
+
use crate::git::raw::ErrorExt as _;
use crate::git::Oid;
use crate::node::device::Device;
use crate::profile::env;
@@ -64,9 +65,8 @@ impl Error {
    /// Whether this error is caused by a reference not being found.
    pub fn is_not_found(&self) -> bool {
        match self {
-
            Self::GitExt(git::Error::NotFound(_)) => true,
-
            Self::GitExt(git::Error::Git(e)) if git::is_not_found_err(e) => true,
-
            Self::Git(e) if git::is_not_found_err(e) => true,
+
            Self::GitExt(e) => e.is_not_found(),
+
            Self::Git(e) => e.is_not_found(),
            _ => false,
        }
    }
@@ -430,7 +430,7 @@ impl SignedRefsAt {
    {
        let at = match RefsAt::new(repo, remote) {
            Ok(RefsAt { at, .. }) => at,
-
            Err(e) if git::is_not_found_err(&e) => return Ok(None),
+
            Err(e) if e.is_not_found() => return Ok(None),
            Err(e) => return Err(e.into()),
        };
        Self::load_at(at, remote, repo).map(Some)