From 54f0542a27e4ccab459d87283e4668d865ddd2bb Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Thu, 26 Feb 2026 15:23:04 +0000 Subject: fix: store tag object OID in tracking ref for annotated tags after push update_remote_refs_pushed was calling peel_to_commit() for all refs, discarding the tag object OID for annotated tags. This caused a mismatch with generate_updated_state, which correctly stores the tag object OID in the nostr state event. ngit sync would then push the commit OID to grasp servers that expected the tag object OID, causing rejections. --- src/bin/git_remote_nostr/push.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'src/bin/git_remote_nostr') diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs index b0e7726..bd1188b 100644 --- a/src/bin/git_remote_nostr/push.rs +++ b/src/bin/git_remote_nostr/push.rs @@ -1524,7 +1524,7 @@ fn update_remote_refs_pushed( refspec: &str, nostr_remote_url: &str, ) -> Result<()> { - let (from, _) = refspec_to_from_to(refspec)?; + let (from, to) = refspec_to_from_to(refspec)?; let target_ref_name = refspec_remote_ref_name(git_repo, refspec, nostr_remote_url)?; @@ -1533,14 +1533,30 @@ fn update_remote_refs_pushed( remote_ref.delete()?; } } else { - let commit = reference_to_commit(git_repo, from) - .context(format!("failed to get commit of reference {from}"))?; + // For annotated tags, store the tag object OID (not the peeled commit) + // to match what generate_updated_state puts in the nostr state event. + // For branches and lightweight tags, store the commit OID as before. + let oid = if to.starts_with("refs/tags/") { + if let Ok(tag_obj) = git_repo + .find_reference(from) + .context(format!("failed to find reference: {from}"))? + .peel(git2::ObjectType::Tag) + { + tag_obj.id() + } else { + reference_to_commit(git_repo, from) + .context(format!("failed to get commit of reference {from}"))? + } + } else { + reference_to_commit(git_repo, from) + .context(format!("failed to get commit of reference {from}"))? + }; if let Ok(mut remote_ref) = git_repo.find_reference(&target_ref_name) { - remote_ref.set_target(commit, "updated by nostr remote helper")?; + remote_ref.set_target(oid, "updated by nostr remote helper")?; } else { git_repo.reference( &target_ref_name, - commit, + oid, false, "created by nostr remote helper", )?; -- cgit v1.2.3