diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-26 11:35:00 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-26 15:26:15 +0000 |
| commit | 237ab4ebcdc5bf58f98958db5375d56baf8046a0 (patch) | |
| tree | d0d2114fbe4b77e2dedcc6191c1622022c8a6695 /src | |
| parent | 5c305e922e19e4ac65c6a1473be67145a1c73f2b (diff) | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/bin/ngit/sub_commands/sync.rs | 12 |
1 files changed, 9 insertions, 3 deletions
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<()> { | |||
| 130 | if missing_refs.contains(nostr_ref_name) { | 130 | if missing_refs.contains(nostr_ref_name) { |
| 131 | continue; | 131 | continue; |
| 132 | } | 132 | } |
| 133 | // strip refs/heads/ or refs/tags/ prefix to get the tracking ref segment | ||
| 134 | // e.g. refs/heads/master -> master, refs/tags/v1.0.0 -> v1.0.0 | ||
| 135 | let tracking_ref_name = nostr_ref_name | ||
| 136 | .strip_prefix("refs/heads/") | ||
| 137 | .or_else(|| nostr_ref_name.strip_prefix("refs/tags/")) | ||
| 138 | .unwrap_or(nostr_ref_name.as_str()); | ||
| 133 | if invalid_nostr_state_ref(nostr_ref_name) { | 139 | if invalid_nostr_state_ref(nostr_ref_name) { |
| 134 | // ensure nostr_state only supports refs/heads and refs/tags/ | 140 | // ensure nostr_state only supports refs/heads and refs/tags/ |
| 135 | // and not refs/heads/prs/* | 141 | // and not refs/heads/prs/* |
| @@ -155,11 +161,11 @@ pub async fn launch(args: &SubCommandArgs) -> Result<()> { | |||
| 155 | // dont try and sync push symbolic refs | 161 | // dont try and sync push symbolic refs |
| 156 | } else if !force_required { | 162 | } else if !force_required { |
| 157 | refspecs.push(format!( | 163 | refspecs.push(format!( |
| 158 | "refs/remotes/{nostr_remote_name}/{nostr_ref_name}:{nostr_ref_name}", | 164 | "refs/remotes/{nostr_remote_name}/{tracking_ref_name}:{nostr_ref_name}", |
| 159 | )); | 165 | )); |
| 160 | } else if *is_grasp_server || args.force { | 166 | } else if *is_grasp_server || args.force { |
| 161 | refspecs.push(format!( | 167 | refspecs.push(format!( |
| 162 | "+refs/remotes/{nostr_remote_name}/{nostr_ref_name}:{nostr_ref_name}", | 168 | "+refs/remotes/{nostr_remote_name}/{tracking_ref_name}:{nostr_ref_name}", |
| 163 | )); | 169 | )); |
| 164 | } else { | 170 | } else { |
| 165 | not_updated.push(nostr_ref_name); | 171 | not_updated.push(nostr_ref_name); |
| @@ -167,7 +173,7 @@ pub async fn launch(args: &SubCommandArgs) -> Result<()> { | |||
| 167 | } else { | 173 | } else { |
| 168 | // add missing refs | 174 | // add missing refs |
| 169 | refspecs.push(format!( | 175 | refspecs.push(format!( |
| 170 | "refs/remotes/{nostr_remote_name}/{nostr_ref_name}:{nostr_ref_name}", | 176 | "refs/remotes/{nostr_remote_name}/{tracking_ref_name}:{nostr_ref_name}", |
| 171 | )); | 177 | )); |
| 172 | } | 178 | } |
| 173 | } | 179 | } |