upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/bin/ngit/sub_commands/apply.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2026-02-12 12:25:10 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2026-02-12 12:25:10 +0000
commitc85ca81767d838797f6a1ab6651e9864c3f961c1 (patch)
tree2519376a5fecb7324346910707f1b378ead3f093 /src/bin/ngit/sub_commands/apply.rs
parent116ab6757ef22779b913a5e1c5e289ba7f3daefb (diff)
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.
Diffstat (limited to 'src/bin/ngit/sub_commands/apply.rs')
-rw-r--r--src/bin/ngit/sub_commands/apply.rs34
1 files changed, 31 insertions, 3 deletions
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 @@
1use std::io::Write; 1use std::{
2 io::Write,
3 process::{Command, Stdio},
4};
2 5
3use anyhow::{Context, Result, bail}; 6use anyhow::{Context, Result, bail};
4use ngit::client::get_all_proposal_patch_pr_pr_update_events_from_cache; 7use 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;
6use nostr::nips::nip19::Nip19; 9use nostr::nips::nip19::Nip19;
7use nostr_sdk::{EventId, FromBech32}; 10use nostr_sdk::{EventId, FromBech32};
8 11
9use crate::client::{Client, Connect, get_repo_ref_from_cache}; 12use crate::client::{Client, Connect, fetching_with_report, get_repo_ref_from_cache};
10use crate::git::{Repo, RepoActions}; 13use crate::git::{Repo, RepoActions};
11use crate::repo_ref::get_repo_coordinates_when_remote_unknown; 14use crate::repo_ref::get_repo_coordinates_when_remote_unknown;
12 15
16fn run_git_fetch(remote_name: &str) -> Result<()> {
17 println!("fetching from {remote_name}...");
18 let exit_status = Command::new("git")
19 .args(["fetch", remote_name])
20 .stdout(Stdio::inherit())
21 .stderr(Stdio::inherit())
22 .status()
23 .context("failed to run git fetch")?;
24
25 if !exit_status.success() {
26 bail!("git fetch {remote_name} exited with error: {exit_status}");
27 }
28 Ok(())
29}
30
13pub async fn launch(id: &str, stdout: bool) -> Result<()> { 31pub async fn launch(id: &str, stdout: bool) -> Result<()> {
14 let event_id = parse_event_id(id)?; 32 let event_id = parse_event_id(id)?;
15 33
@@ -22,7 +40,17 @@ pub async fn launch(id: &str, stdout: bool) -> Result<()> {
22 40
23 let repo_coordinates = get_repo_coordinates_when_remote_unknown(&git_repo, &client).await?; 41 let repo_coordinates = get_repo_coordinates_when_remote_unknown(&git_repo, &client).await?;
24 42
25 crate::client::fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; 43 let nostr_remote = git_repo
44 .get_first_nostr_remote_when_in_ngit_binary()
45 .await
46 .ok()
47 .flatten();
48
49 if let Some((remote_name, _)) = &nostr_remote {
50 run_git_fetch(remote_name)?;
51 } else {
52 fetching_with_report(git_repo_path, &client, &repo_coordinates).await?;
53 }
26 54
27 let repo_ref = get_repo_ref_from_cache(Some(git_repo_path), &repo_coordinates).await?; 55 let repo_ref = get_repo_ref_from_cache(Some(git_repo_path), &repo_coordinates).await?;
28 56