|
87 | 87 | { |
88 | 88 | let mut current_exe = std::env::current_exe().map_err(Error::<E>::NoSelfExe)?; |
89 | 89 | current_exe = current_exe.canonicalize().unwrap_or(current_exe); |
90 | | - tracing::trace!(?current_exe); |
91 | 90 |
|
92 | 91 | // TODO(qix-): Get parent PID of connecting processes to make sure they're us. |
93 | 92 | //let our_pid = std::process::id(); |
@@ -461,125 +460,6 @@ where |
461 | 460 | Err(base_error.into()) |
462 | 461 | } |
463 | 462 |
|
464 | | -/// Signs the given commit-ish in the repository at the given path. |
465 | | -/// Returns the newly signed commit SHA. |
466 | | -/// |
467 | | -/// Any prompts for the user are passed to the asynchronous callback `on_prompt`, |
468 | | -/// which should return the user's response or `None` if the operation should be |
469 | | -/// aborted, in which case an `Err` value is returned from this function. |
470 | | -pub async fn sign_commit<P, E, F, Extra, Fut>( |
471 | | - repo_path: P, |
472 | | - executor: E, |
473 | | - base_commitish: String, |
474 | | - on_prompt: F, |
475 | | - extra: Extra, |
476 | | -) -> Result<String, crate::Error<Error<E>>> |
477 | | -where |
478 | | - P: AsRef<Path>, |
479 | | - E: GitExecutor, |
480 | | - F: FnMut(String, Extra) -> Fut, |
481 | | - Fut: std::future::Future<Output = Option<String>>, |
482 | | - Extra: Send + Clone, |
483 | | -{ |
484 | | - let repo_path = repo_path.as_ref(); |
485 | | - |
486 | | - // First, create a worktree to perform the commit. |
487 | | - let worktree_path = repo_path |
488 | | - .join(".git") |
489 | | - .join("gitbutler") |
490 | | - .join(".wt") |
491 | | - .join(uuid::Uuid::new_v4().to_string()); |
492 | | - let args = [ |
493 | | - "worktree", |
494 | | - "add", |
495 | | - "--detach", |
496 | | - "--no-checkout", |
497 | | - worktree_path.to_str().unwrap(), |
498 | | - base_commitish.as_str(), |
499 | | - ]; |
500 | | - let (status, stdout, stderr) = executor |
501 | | - .execute(&args, repo_path, None) |
502 | | - .await |
503 | | - .map_err(Error::<E>::Exec)?; |
504 | | - if status != 0 { |
505 | | - return Err(Error::<E>::Failed { |
506 | | - status, |
507 | | - args: args.into_iter().map(Into::into).collect(), |
508 | | - stdout, |
509 | | - stderr, |
510 | | - })?; |
511 | | - } |
512 | | - |
513 | | - // Now, perform the commit. |
514 | | - let args = [ |
515 | | - "commit", |
516 | | - "--amend", |
517 | | - "-S", |
518 | | - "-o", |
519 | | - "--no-edit", |
520 | | - "--no-verify", |
521 | | - "--no-post-rewrite", |
522 | | - "--allow-empty", |
523 | | - "--allow-empty-message", |
524 | | - ]; |
525 | | - let (status, stdout, stderr) = execute_with_auth_harness( |
526 | | - HarnessEnv::Repo(&worktree_path), |
527 | | - &executor, |
528 | | - &args, |
529 | | - None, |
530 | | - on_prompt, |
531 | | - extra, |
532 | | - ) |
533 | | - .await?; |
534 | | - if status != 0 { |
535 | | - return Err(Error::<E>::Failed { |
536 | | - status, |
537 | | - args: args.into_iter().map(Into::into).collect(), |
538 | | - stdout, |
539 | | - stderr, |
540 | | - })?; |
541 | | - } |
542 | | - |
543 | | - // Get the commit hash that was generated |
544 | | - let args = ["rev-parse", "--verify", "HEAD"]; |
545 | | - let (status, stdout, stderr) = executor |
546 | | - .execute(&args, &worktree_path, None) |
547 | | - .await |
548 | | - .map_err(Error::<E>::Exec)?; |
549 | | - if status != 0 { |
550 | | - return Err(Error::<E>::Failed { |
551 | | - status, |
552 | | - args: args.into_iter().map(Into::into).collect(), |
553 | | - stdout, |
554 | | - stderr, |
555 | | - })?; |
556 | | - } |
557 | | - |
558 | | - let commit_hash = stdout.trim().to_string(); |
559 | | - |
560 | | - // Finally, remove the worktree |
561 | | - let args = [ |
562 | | - "worktree", |
563 | | - "remove", |
564 | | - "--force", |
565 | | - worktree_path.to_str().unwrap(), |
566 | | - ]; |
567 | | - let (status, stdout, stderr) = executor |
568 | | - .execute(&args, repo_path, None) |
569 | | - .await |
570 | | - .map_err(Error::<E>::Exec)?; |
571 | | - if status != 0 { |
572 | | - return Err(Error::<E>::Failed { |
573 | | - status, |
574 | | - args: args.into_iter().map(Into::into).collect(), |
575 | | - stdout, |
576 | | - stderr, |
577 | | - })?; |
578 | | - } |
579 | | - |
580 | | - Ok(commit_hash) |
581 | | -} |
582 | | - |
583 | 463 | fn get_core_sshcommand<P>(harness_env: &HarnessEnv<P>) -> anyhow::Result<Option<String>> |
584 | 464 | where |
585 | 465 | P: AsRef<Path>, |
|
0 commit comments