diff --git a/radicle-surf/src/error.rs b/radicle-surf/src/error.rs index cac2a46..7bd5954 100644 --- a/radicle-surf/src/error.rs +++ b/radicle-surf/src/error.rs @@ -21,6 +21,7 @@ use crate::{commit, diff, fs, glob, namespace, refs, repo}; use thiserror::Error; +/// The crate level error type that wraps up module level error types. #[derive(Debug, Error)] #[non_exhaustive] pub enum Error { diff --git a/radicle-surf/src/lib.rs b/radicle-surf/src/lib.rs index 989319c..8b3b5bd 100644 --- a/radicle-surf/src/lib.rs +++ b/radicle-surf/src/lib.rs @@ -36,7 +36,7 @@ pub use git_ref_format; /// Represents an object id in Git. Re-exported from `radicle-git-ext`. -pub use radicle_git_ext::Oid; +pub type Oid = radicle_git_ext::Oid; pub mod blob; pub mod diff; diff --git a/radicle-surf/src/repo.rs b/radicle-surf/src/repo.rs index 9ef689a..c6557a8 100644 --- a/radicle-surf/src/repo.rs +++ b/radicle-surf/src/repo.rs @@ -375,19 +375,22 @@ impl Repository { /// /// # Arguments /// - /// `commit_oid` - The object ID of the commit /// `field` - the name of the header field containing the signature block; /// pass `None` to extract the default 'gpgsig' pub fn extract_signature( &self, - commit_oid: &Oid, + commit: impl ToCommit, field: Option<&str>, ) -> Result, Error> { // Match is necessary here because according to the documentation for // git_commit_extract_signature at // https://libgit2.org/libgit2/#HEAD/group/commit/git_commit_extract_signature // the return value for a commit without a signature will be GIT_ENOTFOUND - match self.inner.extract_signature(commit_oid, field) { + let commit = commit + .to_commit(self) + .map_err(|e| Error::ToCommit(e.into()))?; + + match self.inner.extract_signature(&commit.id, field) { Err(error) => { if error.code() == git2::ErrorCode::NotFound { Ok(None) diff --git a/radicle-surf/t/src/code_browsing.rs b/radicle-surf/t/src/code_browsing.rs index 60e1f23..2402f36 100644 --- a/radicle-surf/t/src/code_browsing.rs +++ b/radicle-surf/t/src/code_browsing.rs @@ -80,3 +80,21 @@ fn test_commit_history() { assert_eq!(h1.head().id, h2.head().id); } + +#[test] +fn test_commit_signature() { + let repo = Repository::open(GIT_PLATINUM).unwrap(); + let commit_with_signature = "e24124b7538658220b5aaf3b6ef53758f0a106dc"; + let signature = repo.extract_signature(commit_with_signature, None).unwrap(); + assert!(signature.is_some()); + + let commit_without_signature = "80bacafba303bf0cdf6142921f430ff265f25095"; + let signature = repo + .extract_signature(commit_without_signature, None) + .unwrap(); + assert!(signature.is_none()); + + let commit_nonexist = "8080808080"; + let signature = repo.extract_signature(commit_nonexist, None); + assert!(signature.is_err()); +}