diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-13 10:51:25 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-13 10:51:25 +0000 |
| commit | 40b439ae4d69b858274be51dd5af513c3b4f46f0 (patch) | |
| tree | 64beb8589b8a2da5aee7aecf8dc9564e21d676d0 /src/bin/ngit/sub_commands/apply.rs | |
| parent | cfd8cc19b6a81ad78bc30d5b21cefe21d574d09e (diff) | |
feat: add spinner for git fetch in non-verbose mode
Shows a progress spinner when fetching from git remotes in non-verbose mode.
Suppresses git fetch output and listing messages when not in verbose mode.
Uses NGITTEST environment variable for test timeouts.
Diffstat (limited to 'src/bin/ngit/sub_commands/apply.rs')
| -rw-r--r-- | src/bin/ngit/sub_commands/apply.rs | 55 |
1 files changed, 48 insertions, 7 deletions
diff --git a/src/bin/ngit/sub_commands/apply.rs b/src/bin/ngit/sub_commands/apply.rs index 4ed6caa..2d5d8d5 100644 --- a/src/bin/ngit/sub_commands/apply.rs +++ b/src/bin/ngit/sub_commands/apply.rs | |||
| @@ -1,9 +1,11 @@ | |||
| 1 | use std::{ | 1 | use std::{ |
| 2 | io::Write, | 2 | io::Write, |
| 3 | process::{Command, Stdio}, | 3 | process::{Command, Stdio}, |
| 4 | time::Duration, | ||
| 4 | }; | 5 | }; |
| 5 | 6 | ||
| 6 | use anyhow::{Context, Result, bail}; | 7 | use anyhow::{Context, Result, bail}; |
| 8 | use indicatif::{ProgressBar, ProgressStyle}; | ||
| 7 | use ngit::{ | 9 | use ngit::{ |
| 8 | client::get_all_proposal_patch_pr_pr_update_events_from_cache, | 10 | client::get_all_proposal_patch_pr_pr_update_events_from_cache, |
| 9 | git_events::get_pr_tip_event_or_most_recent_patch_with_ancestors, | 11 | git_events::get_pr_tip_event_or_most_recent_patch_with_ancestors, |
| @@ -18,16 +20,55 @@ use crate::{ | |||
| 18 | }; | 20 | }; |
| 19 | 21 | ||
| 20 | fn run_git_fetch(remote_name: &str) -> Result<()> { | 22 | fn run_git_fetch(remote_name: &str) -> Result<()> { |
| 21 | println!("fetching from {remote_name}..."); | 23 | let verbose = ngit::client::is_verbose(); |
| 22 | let exit_status = Command::new("git") | 24 | if verbose { |
| 25 | println!("fetching from {remote_name}..."); | ||
| 26 | } | ||
| 27 | |||
| 28 | let spinner = if verbose { | ||
| 29 | None | ||
| 30 | } else { | ||
| 31 | let pb = ProgressBar::new_spinner() | ||
| 32 | .with_style( | ||
| 33 | ProgressStyle::with_template("{spinner} {msg}") | ||
| 34 | .unwrap() | ||
| 35 | .tick_chars("⠁⠂⠄⡀⢀⠠⠐⠈"), | ||
| 36 | ) | ||
| 37 | .with_message(format!("Fetching from {remote_name}...")); | ||
| 38 | pb.enable_steady_tick(Duration::from_millis(100)); | ||
| 39 | Some(pb) | ||
| 40 | }; | ||
| 41 | |||
| 42 | let output = Command::new("git") | ||
| 23 | .args(["fetch", remote_name]) | 43 | .args(["fetch", remote_name]) |
| 24 | .stdout(Stdio::inherit()) | 44 | .stdout(if verbose { |
| 25 | .stderr(Stdio::inherit()) | 45 | Stdio::inherit() |
| 26 | .status() | 46 | } else { |
| 47 | Stdio::piped() | ||
| 48 | }) | ||
| 49 | .stderr(if verbose { | ||
| 50 | Stdio::inherit() | ||
| 51 | } else { | ||
| 52 | Stdio::piped() | ||
| 53 | }) | ||
| 54 | .output() | ||
| 27 | .context("failed to run git fetch")?; | 55 | .context("failed to run git fetch")?; |
| 28 | 56 | ||
| 29 | if !exit_status.success() { | 57 | if let Some(spinner) = spinner { |
| 30 | bail!("git fetch {remote_name} exited with error: {exit_status}"); | 58 | spinner.finish_and_clear(); |
| 59 | } | ||
| 60 | |||
| 61 | if !output.status.success() { | ||
| 62 | if !verbose { | ||
| 63 | let stderr = String::from_utf8_lossy(&output.stderr); | ||
| 64 | if !stderr.is_empty() { | ||
| 65 | eprintln!("{stderr}"); | ||
| 66 | } | ||
| 67 | } | ||
| 68 | bail!( | ||
| 69 | "git fetch {remote_name} exited with error: {}", | ||
| 70 | output.status | ||
| 71 | ); | ||
| 31 | } | 72 | } |
| 32 | Ok(()) | 73 | Ok(()) |
| 33 | } | 74 | } |