diff options
Diffstat (limited to 'src/bin/ngit/sub_commands/apply.rs')
| -rw-r--r-- | src/bin/ngit/sub_commands/apply.rs | 34 |
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 @@ | |||
| 1 | use std::io::Write; | 1 | use std::{ |
| 2 | io::Write, | ||
| 3 | process::{Command, Stdio}, | ||
| 4 | }; | ||
| 2 | 5 | ||
| 3 | use anyhow::{Context, Result, bail}; | 6 | use anyhow::{Context, Result, bail}; |
| 4 | use ngit::client::get_all_proposal_patch_pr_pr_update_events_from_cache; | 7 | 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; | |||
| 6 | use nostr::nips::nip19::Nip19; | 9 | use nostr::nips::nip19::Nip19; |
| 7 | use nostr_sdk::{EventId, FromBech32}; | 10 | use nostr_sdk::{EventId, FromBech32}; |
| 8 | 11 | ||
| 9 | use crate::client::{Client, Connect, get_repo_ref_from_cache}; | 12 | use crate::client::{Client, Connect, fetching_with_report, get_repo_ref_from_cache}; |
| 10 | use crate::git::{Repo, RepoActions}; | 13 | use crate::git::{Repo, RepoActions}; |
| 11 | use crate::repo_ref::get_repo_coordinates_when_remote_unknown; | 14 | use crate::repo_ref::get_repo_coordinates_when_remote_unknown; |
| 12 | 15 | ||
| 16 | fn 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 | |||
| 13 | pub async fn launch(id: &str, stdout: bool) -> Result<()> { | 31 | pub 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 | ||