diff --git a/crates/gitbutler-core/src/askpass.rs b/crates/gitbutler-core/src/askpass.rs index 6b85f7cc4..5bf968f7a 100644 --- a/crates/gitbutler-core/src/askpass.rs +++ b/crates/gitbutler-core/src/askpass.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, sync::Arc}; +use std::{collections::HashMap, path::Path, sync::Arc}; use serde::Serialize; use tokio::sync::{oneshot, Mutex}; @@ -40,6 +40,7 @@ pub struct AskpassRequest { pub enum Context { Push { branch_id: Option }, Fetch { action: String }, + SignedCommit { branch_id: Option }, } #[derive(Clone)] @@ -85,3 +86,35 @@ impl AskpassBroker { } } } + +async fn handle_git_prompt_commit_sign_sync( + prompt: String, + branch_id: Option, +) -> Option { + tracing::info!("received prompt for synchronous signed commit {branch_id:?}: {prompt:?}"); + get_broker() + .submit_prompt(prompt, Context::SignedCommit { branch_id }) + .await +} + +/// Utility to synchronously sign a commit. +/// Uses the Tokio runner to run the async function, +/// and the global askpass broker to handle any prompts. +pub fn sign_commit_sync( + repo_path: impl AsRef, + base_commitish: impl AsRef, + branch_id: Option, +) -> Result { + // Run as sync + tokio::runtime::Builder::new_multi_thread() + .enable_all() + .build() + .unwrap() + .block_on(gitbutler_git::sign_commit( + repo_path, + gitbutler_git::tokio::TokioExecutor, + base_commitish.as_ref().to_string(), + handle_git_prompt_commit_sign_sync, + branch_id, + )) +}