From c85ca81767d838797f6a1ab6651e9864c3f961c1 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Thu, 12 Feb 2026 12:25:10 +0000 Subject: fix: set up branch tracking when checking out proposals When a nostr:// remote exists, run git fetch instead of internal fetch to populate remote tracking refs. Then checkout the remote branch with proper upstream tracking so git pull works correctly. --- src/bin/ngit/sub_commands/apply.rs | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'src/bin/ngit/sub_commands/apply.rs') diff --git a/src/bin/ngit/sub_commands/apply.rs b/src/bin/ngit/sub_commands/apply.rs index d32cd4f..fd9eae3 100644 --- a/src/bin/ngit/sub_commands/apply.rs +++ b/src/bin/ngit/sub_commands/apply.rs @@ -1,4 +1,7 @@ -use std::io::Write; +use std::{ + io::Write, + process::{Command, Stdio}, +}; use anyhow::{Context, Result, bail}; use ngit::client::get_all_proposal_patch_pr_pr_update_events_from_cache; @@ -6,10 +9,25 @@ use ngit::git_events::get_pr_tip_event_or_most_recent_patch_with_ancestors; use nostr::nips::nip19::Nip19; use nostr_sdk::{EventId, FromBech32}; -use crate::client::{Client, Connect, get_repo_ref_from_cache}; +use crate::client::{Client, Connect, fetching_with_report, get_repo_ref_from_cache}; use crate::git::{Repo, RepoActions}; use crate::repo_ref::get_repo_coordinates_when_remote_unknown; +fn run_git_fetch(remote_name: &str) -> Result<()> { + println!("fetching from {remote_name}..."); + let exit_status = Command::new("git") + .args(["fetch", remote_name]) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .status() + .context("failed to run git fetch")?; + + if !exit_status.success() { + bail!("git fetch {remote_name} exited with error: {exit_status}"); + } + Ok(()) +} + pub async fn launch(id: &str, stdout: bool) -> Result<()> { let event_id = parse_event_id(id)?; @@ -22,7 +40,17 @@ pub async fn launch(id: &str, stdout: bool) -> Result<()> { let repo_coordinates = get_repo_coordinates_when_remote_unknown(&git_repo, &client).await?; - crate::client::fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; + let nostr_remote = git_repo + .get_first_nostr_remote_when_in_ngit_binary() + .await + .ok() + .flatten(); + + if let Some((remote_name, _)) = &nostr_remote { + run_git_fetch(remote_name)?; + } else { + fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; + } let repo_ref = get_repo_ref_from_cache(Some(git_repo_path), &repo_coordinates).await?; -- cgit v1.2.3