diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-12 12:25:10 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-12 12:25:10 +0000 |
| commit | c85ca81767d838797f6a1ab6651e9864c3f961c1 (patch) | |
| tree | 2519376a5fecb7324346910707f1b378ead3f093 /src/bin/ngit/sub_commands/list.rs | |
| parent | 116ab6757ef22779b913a5e1c5e289ba7f3daefb (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/list.rs')
| -rw-r--r-- | src/bin/ngit/sub_commands/list.rs | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/src/bin/ngit/sub_commands/list.rs b/src/bin/ngit/sub_commands/list.rs index 7873fae..6d78a1f 100644 --- a/src/bin/ngit/sub_commands/list.rs +++ b/src/bin/ngit/sub_commands/list.rs | |||
| @@ -1,4 +1,7 @@ | |||
| 1 | use std::{collections::HashSet, io::Write, ops::Add}; | 1 | use std::{ |
| 2 | collections::HashSet, io::Write, ops::Add, | ||
| 3 | process::{Command, Stdio}, | ||
| 4 | }; | ||
| 2 | 5 | ||
| 3 | use anyhow::{Context, Result, bail}; | 6 | use anyhow::{Context, Result, bail}; |
| 4 | use ngit::{ | 7 | use ngit::{ |
| @@ -31,6 +34,21 @@ use crate::{ | |||
| 31 | repo_ref::get_repo_coordinates_when_remote_unknown, | 34 | repo_ref::get_repo_coordinates_when_remote_unknown, |
| 32 | }; | 35 | }; |
| 33 | 36 | ||
| 37 | fn run_git_fetch(remote_name: &str) -> Result<()> { | ||
| 38 | println!("fetching from {remote_name}..."); | ||
| 39 | let exit_status = Command::new("git") | ||
| 40 | .args(["fetch", remote_name]) | ||
| 41 | .stdout(Stdio::inherit()) | ||
| 42 | .stderr(Stdio::inherit()) | ||
| 43 | .status() | ||
| 44 | .context("failed to run git fetch")?; | ||
| 45 | |||
| 46 | if !exit_status.success() { | ||
| 47 | bail!("git fetch {remote_name} exited with error: {exit_status}"); | ||
| 48 | } | ||
| 49 | Ok(()) | ||
| 50 | } | ||
| 51 | |||
| 34 | #[allow(clippy::too_many_lines)] | 52 | #[allow(clippy::too_many_lines)] |
| 35 | pub async fn launch(status: String, json: bool, id: Option<String>) -> Result<()> { | 53 | pub async fn launch(status: String, json: bool, id: Option<String>) -> Result<()> { |
| 36 | if std::env::var("NGIT_INTERACTIVE_MODE").is_ok() { | 54 | if std::env::var("NGIT_INTERACTIVE_MODE").is_ok() { |
| @@ -44,7 +62,17 @@ pub async fn launch(status: String, json: bool, id: Option<String>) -> Result<() | |||
| 44 | 62 | ||
| 45 | let repo_coordinates = get_repo_coordinates_when_remote_unknown(&git_repo, &client).await?; | 63 | let repo_coordinates = get_repo_coordinates_when_remote_unknown(&git_repo, &client).await?; |
| 46 | 64 | ||
| 47 | fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; | 65 | let nostr_remote = git_repo |
| 66 | .get_first_nostr_remote_when_in_ngit_binary() | ||
| 67 | .await | ||
| 68 | .ok() | ||
| 69 | .flatten(); | ||
| 70 | |||
| 71 | if let Some((remote_name, _)) = &nostr_remote { | ||
| 72 | run_git_fetch(remote_name)?; | ||
| 73 | } else { | ||
| 74 | fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; | ||
| 75 | } | ||
| 48 | 76 | ||
| 49 | let repo_ref = get_repo_ref_from_cache(Some(git_repo_path), &repo_coordinates).await?; | 77 | let repo_ref = get_repo_ref_from_cache(Some(git_repo_path), &repo_coordinates).await?; |
| 50 | 78 | ||
| @@ -285,7 +313,17 @@ async fn launch_interactive() -> Result<()> { | |||
| 285 | 313 | ||
| 286 | let repo_coordinates = get_repo_coordinates_when_remote_unknown(&git_repo, &client).await?; | 314 | let repo_coordinates = get_repo_coordinates_when_remote_unknown(&git_repo, &client).await?; |
| 287 | 315 | ||
| 288 | fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; | 316 | let nostr_remote = git_repo |
| 317 | .get_first_nostr_remote_when_in_ngit_binary() | ||
| 318 | .await | ||
| 319 | .ok() | ||
| 320 | .flatten(); | ||
| 321 | |||
| 322 | if let Some((remote_name, _)) = &nostr_remote { | ||
| 323 | run_git_fetch(remote_name)?; | ||
| 324 | } else { | ||
| 325 | fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; | ||
| 326 | } | ||
| 289 | 327 | ||
| 290 | let repo_ref = get_repo_ref_from_cache(Some(git_repo_path), &repo_coordinates).await?; | 328 | let repo_ref = get_repo_ref_from_cache(Some(git_repo_path), &repo_coordinates).await?; |
| 291 | 329 | ||