upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/git.rs53
1 files changed, 45 insertions, 8 deletions
diff --git a/src/git.rs b/src/git.rs
index 7292508..41520c6 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -465,14 +465,51 @@ fn apply_patch(git_repo: &Repo, patch: &nostr::Event) -> Result<()> {
465 index.add_all(["."], git2::IndexAddOption::DEFAULT, None)?; 465 index.add_all(["."], git2::IndexAddOption::DEFAULT, None)?;
466 index.write()?; 466 index.write()?;
467 467
468 git_repo.git_repo.commit( 468 let pgp_sig = if let Ok(pgp_sig) = tag_value(patch, "commit-sig") {
469 Some("HEAD"), 469 if pgp_sig.is_empty() {
470 &extract_sig_from_patch_tags(&patch.tags, "author")?, 470 None
471 &extract_sig_from_patch_tags(&patch.tags, "committer")?, 471 } else {
472 tag_value(patch, "description")?.as_str(), 472 Some(pgp_sig)
473 &git_repo.git_repo.find_tree(index.write_tree()?)?, 473 }
474 &[&prev_oid], 474 } else {
475 )?; 475 None
476 };
477
478 if let Some(pgp_sig) = pgp_sig {
479 let commit_buff = git_repo.git_repo.commit_create_buffer(
480 &extract_sig_from_patch_tags(&patch.tags, "author")?,
481 &extract_sig_from_patch_tags(&patch.tags, "committer")?,
482 tag_value(patch, "description")?.as_str(),
483 &git_repo.git_repo.find_tree(index.write_tree()?)?,
484 &[&prev_oid],
485 )?;
486 let gpg_commit_id = git_repo.git_repo.commit_signed(
487 commit_buff.as_str().unwrap(),
488 pgp_sig.as_str(),
489 None,
490 )?;
491 git_repo.git_repo.reset(
492 &git_repo.git_repo.find_object(gpg_commit_id, None)?,
493 git2::ResetType::Mixed,
494 None,
495 )?;
496 if gpg_commit_id.to_string().eq(&tag_value(patch, "commit")?) {
497 return Ok(());
498 }
499 } else {
500 git_repo.git_repo.commit(
501 Some("HEAD"),
502 &extract_sig_from_patch_tags(&patch.tags, "author")?,
503 &extract_sig_from_patch_tags(&patch.tags, "committer")?,
504 tag_value(patch, "description")?.as_str(),
505 &git_repo.git_repo.find_tree(index.write_tree()?)?,
506 &[&prev_oid],
507 )?;
508 }
509 validate_patch_applied(git_repo, patch)
510}
511
512fn validate_patch_applied(git_repo: &Repo, patch: &nostr::Event) -> Result<()> {
476 // end of stage and commit 513 // end of stage and commit
477 // check commit applied 514 // check commit applied
478 if git_repo 515 if git_repo