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. --- CHANGELOG.md | 2 ++ src/bin/git_remote_nostr/push.rs | 26 +++++++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4130ce2..31716ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `git-remote-nostr` list now advertises the newest state event whose OIDs are all confirmed present on a git server or locally, rather than unconditionally using the latest nostr state event; this prevents catastrophic fetch/clone failures when a state event was published before the corresponding git push completed - Tag tracking refs written with wrong path (`refs/remotes/origin/refs/tags/v1.0.0` instead of `refs/remotes/origin/v1.0.0`) after a push via `git-remote-nostr`, causing `ngit sync` to fail with "src refspec does not match any existing object" when syncing tags +- Annotated tag tracking refs stored with the peeled commit OID instead of the tag object OID after a push via `git-remote-nostr`; this caused `ngit sync` to push the wrong object to grasp servers, which rejected it because the nostr state event referenced the tag object OID +- `ngit sync --verbose` detailed per-relay view not shown; `--verbose` flag was ignored due to a logic error in `send_events` - `ngit sync` using wrong refspec source (`refs/remotes/origin/refs/heads/master` instead of `refs/remotes/origin/master`), causing sync to fail with "src refspec does not match any existing object" - State event publish failures silently swallowed during push; summary now shows `"Published to X/N relays (failed: relay1 relay2)"` instead of unconditional success message - Grasp servers whose internal relay did not receive the state event are now skipped during push, with a clear warning; push fails with an error message when no servers remain 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