8000 Provide an example for signed commits · Issue #72 · gitext-rs/git2-ext · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Provide an example for signed commits #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
davinkevin opened this issue Jun 19, 2024 · 2 comments
Open

Provide an example for signed commits #72

davinkevin opened this issue Jun 19, 2024 · 2 comments
Labels
enhancement Improve the expected

Comments

@davinkevin
Copy link

Hello 👋

Thank you for the project, it has been very helpful to understand how to do things with git2-rs.

However, I struggled to use the function commit, especially for signed commits. I searched for example, but no example or test so far.

My problem was related to transform the result of UserSign::from_config(&repo, &repo.config()?) into the expected parameter of the commit function, which has to be of type Option<&dyn Sign>.

let signer = UserSign::from_config(&repo, &repo.config()?)
    .ok()
    .as_ref();

let new_oid = commit(
    &repo,
    &commit.author(),
    &commit.committer(),
    &message[..],
    &commit.tree()?,
    &[&repo.find_commit(parent_oid.unwrap_or(first_parent))?],
    signer
)?;

And with that, and many other tries, always a compiler error.

I found many things (example), but nothing trivial as the library is, so I prefer opening an issue in case of an error in the original code.

I just ask for a test or an example of this code.

Thank you!

@epage
Copy link
Contributor
epage commented Jun 19, 2024

I do

self.sign.as_ref().map(|s| s as &dyn git2_ext::ops::Sign)

See https://github.com/gitext-rs/git-stack/blob/f42093a0d6f77744195f23de47617f65d80e2b60/src/git/repo.rs#L423C13-L423C70

Would appreciate examples being added but likely not going to get to it myself for some time.

@davinkevin
Copy link
Author

Thank you for the example @epage!

I solved my issue by doing this:

let signer = UserSign::from_config(&repo, &repo.config()?);
let sign = signer
    .as_ref()
    .map(|s| s as &dyn Sign)
    .ok();

let oid = extCommit(
    &repo,
    &author,
    &committer,
    &message,
    &tree,
    &parent_refs[..],
    sign,
)?;

The missing part was the first let, which can't be inlined with the second one, because of the borrow checker (I'm kind of n00b in rust).

@epage epage added the enhancement Improve the expected label Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improve the expected
Projects
None yet
Development

No branches or pull requests

2 participants
0