From 237ab4ebcdc5bf58f98958db5375d56baf8046a0 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Thu, 26 Feb 2026 11:35:00 +0000 Subject: fix: correct refspec source in ngit sync to strip refs/heads/ prefix When syncing, the nostr state stores refs with full names like refs/heads/master and refs/tags/v1.0.0. Git tracking refs strip the refs/heads/ prefix, so the tracking ref lives at refs/remotes/origin/master not refs/remotes/origin/refs/heads/master. The sync code was interpolating the full nostr_ref_name into the source side of the refspec, producing the invalid double-prefixed path. Strip refs/heads/ or refs/tags/ before constructing the tracking ref segment, consistent with how git_remote_nostr/push.rs already handles this. --- src/bin/ngit/sub_commands/sync.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/bin/ngit/sub_commands') diff --git a/src/bin/ngit/sub_commands/sync.rs b/src/bin/ngit/sub_commands/sync.rs index b377ab4..99cd2d8 100644 --- a/src/bin/ngit/sub_commands/sync.rs +++ b/src/bin/ngit/sub_commands/sync.rs @@ -130,6 +130,12 @@ pub async fn launch(args: &SubCommandArgs) -> Result<()> { if missing_refs.contains(nostr_ref_name) { continue; } + // strip refs/heads/ or refs/tags/ prefix to get the tracking ref segment + // e.g. refs/heads/master -> master, refs/tags/v1.0.0 -> v1.0.0 + let tracking_ref_name = nostr_ref_name + .strip_prefix("refs/heads/") + .or_else(|| nostr_ref_name.strip_prefix("refs/tags/")) + .unwrap_or(nostr_ref_name.as_str()); if invalid_nostr_state_ref(nostr_ref_name) { // ensure nostr_state only supports refs/heads and refs/tags/ // and not refs/heads/prs/* @@ -155,11 +161,11 @@ pub async fn launch(args: &SubCommandArgs) -> Result<()> { // dont try and sync push symbolic refs } else if !force_required { refspecs.push(format!( - "refs/remotes/{nostr_remote_name}/{nostr_ref_name}:{nostr_ref_name}", + "refs/remotes/{nostr_remote_name}/{tracking_ref_name}:{nostr_ref_name}", )); } else if *is_grasp_server || args.force { refspecs.push(format!( - "+refs/remotes/{nostr_remote_name}/{nostr_ref_name}:{nostr_ref_name}", + "+refs/remotes/{nostr_remote_name}/{tracking_ref_name}:{nostr_ref_name}", )); } else { not_updated.push(nostr_ref_name); @@ -167,7 +173,7 @@ pub async fn launch(args: &SubCommandArgs) -> Result<()> { } else { // add missing refs refspecs.push(format!( - "refs/remotes/{nostr_remote_name}/{nostr_ref_name}:{nostr_ref_name}", + "refs/remotes/{nostr_remote_name}/{tracking_ref_name}:{nostr_ref_name}", )); } } -- cgit v1.2.3