mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2025-01-04 15:53:30 +03:00
add synchronous signed git commit utility function
This commit is contained in:
parent
b9aae21b97
commit
ca714084b1
@ -1,4 +1,4 @@
|
|||||||
use std::{collections::HashMap, sync::Arc};
|
use std::{collections::HashMap, path::Path, sync::Arc};
|
||||||
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use tokio::sync::{oneshot, Mutex};
|
use tokio::sync::{oneshot, Mutex};
|
||||||
@ -40,6 +40,7 @@ pub struct AskpassRequest {
|
|||||||
pub enum Context {
|
pub enum Context {
|
||||||
Push { branch_id: Option<BranchId> },
|
Push { branch_id: Option<BranchId> },
|
||||||
Fetch { action: String },
|
Fetch { action: String },
|
||||||
|
SignedCommit { branch_id: Option<BranchId> },
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -85,3 +86,35 @@ impl AskpassBroker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn handle_git_prompt_commit_sign_sync(
|
||||||
|
prompt: String,
|
||||||
|
branch_id: Option<BranchId>,
|
||||||
|
) -> Option<String> {
|
||||||
|
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<P, Extra>(
|
||||||
|
repo_path: impl AsRef<Path>,
|
||||||
|
base_commitish: impl AsRef<str>,
|
||||||
|
branch_id: Option<BranchId>,
|
||||||
|
) -> Result<String, impl std::error::Error> {
|
||||||
|
// 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,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user