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 | |
| 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')
| -rw-r--r-- | src/bin/git_remote_nostr/list.rs | 6 | ||||
| -rw-r--r-- | src/bin/git_remote_nostr/main.rs | 13 | ||||
| -rw-r--r-- | src/bin/ngit/main.rs | 6 | ||||
| -rw-r--r-- | src/bin/ngit/sub_commands/apply.rs | 55 | ||||
| -rw-r--r-- | src/bin/ngit/sub_commands/checkout.rs | 55 | ||||
| -rw-r--r-- | src/bin/ngit/sub_commands/list.rs | 60 |
6 files changed, 159 insertions, 36 deletions
diff --git a/src/bin/git_remote_nostr/list.rs b/src/bin/git_remote_nostr/list.rs index 7753ba1..4a7c1ec 100644 --- a/src/bin/git_remote_nostr/list.rs +++ b/src/bin/git_remote_nostr/list.rs | |||
| @@ -4,7 +4,7 @@ use anyhow::{Context, Result}; | |||
| 4 | use client::get_state_from_cache; | 4 | use client::get_state_from_cache; |
| 5 | use git::RepoActions; | 5 | use git::RepoActions; |
| 6 | use ngit::{ | 6 | use ngit::{ |
| 7 | client, | 7 | client::{self, is_verbose}, |
| 8 | fetch::fetch_from_git_server, | 8 | fetch::fetch_from_git_server, |
| 9 | git::{self}, | 9 | git::{self}, |
| 10 | git_events::{KIND_PULL_REQUEST, KIND_PULL_REQUEST_UPDATE, event_to_cover_letter, tag_value}, | 10 | git_events::{KIND_PULL_REQUEST, KIND_PULL_REQUEST_UPDATE, event_to_cover_letter, tag_value}, |
| @@ -27,7 +27,9 @@ pub async fn run_list( | |||
| 27 | 27 | ||
| 28 | let term = console::Term::stderr(); | 28 | let term = console::Term::stderr(); |
| 29 | 29 | ||
| 30 | term.write_line("git servers: listing refs...")?; | 30 | if is_verbose() { |
| 31 | term.write_line("git servers: listing refs...")?; | ||
| 32 | } | ||
| 31 | let remote_states = list_from_remotes( | 33 | let remote_states = list_from_remotes( |
| 32 | &term, | 34 | &term, |
| 33 | git_repo, | 35 | git_repo, |
diff --git a/src/bin/git_remote_nostr/main.rs b/src/bin/git_remote_nostr/main.rs index b26981d..3663d5b 100644 --- a/src/bin/git_remote_nostr/main.rs +++ b/src/bin/git_remote_nostr/main.rs | |||
| @@ -12,7 +12,7 @@ use std::{ | |||
| 12 | }; | 12 | }; |
| 13 | 13 | ||
| 14 | use anyhow::{Context, Result, bail}; | 14 | use anyhow::{Context, Result, bail}; |
| 15 | use client::{Connect, consolidate_fetch_reports, get_repo_ref_from_cache}; | 15 | use client::{Connect, consolidate_fetch_reports, get_repo_ref_from_cache, is_verbose}; |
| 16 | use git::{RepoActions, nostr_url::NostrUrlDecoded}; | 16 | use git::{RepoActions, nostr_url::NostrUrlDecoded}; |
| 17 | use ngit::{ | 17 | use ngit::{ |
| 18 | client::{self, Params}, | 18 | client::{self, Params}, |
| @@ -156,7 +156,10 @@ async fn fetching_with_report_for_helper( | |||
| 156 | trusted_maintainer_coordinate: &Nip19Coordinate, | 156 | trusted_maintainer_coordinate: &Nip19Coordinate, |
| 157 | ) -> Result<()> { | 157 | ) -> Result<()> { |
| 158 | let term = console::Term::stderr(); | 158 | let term = console::Term::stderr(); |
| 159 | term.write_line("nostr: fetching...")?; | 159 | let verbose = is_verbose(); |
| 160 | if verbose { | ||
| 161 | term.write_line("nostr: fetching...")?; | ||
| 162 | } | ||
| 160 | let (relay_reports, progress_reporter) = client | 163 | let (relay_reports, progress_reporter) = client |
| 161 | .fetch_all( | 164 | .fetch_all( |
| 162 | Some(git_repo_path), | 165 | Some(git_repo_path), |
| @@ -166,10 +169,12 @@ async fn fetching_with_report_for_helper( | |||
| 166 | .await?; | 169 | .await?; |
| 167 | let report = consolidate_fetch_reports(relay_reports); | 170 | let report = consolidate_fetch_reports(relay_reports); |
| 168 | if report.to_string().is_empty() { | 171 | if report.to_string().is_empty() { |
| 169 | term.write_line("nostr: no updates")?; | 172 | if verbose { |
| 173 | term.write_line("nostr: no updates")?; | ||
| 174 | } | ||
| 170 | } else { | 175 | } else { |
| 171 | term.write_line(&format!("nostr updates: {report}"))?; | 176 | term.write_line(&format!("nostr updates: {report}"))?; |
| 172 | } | 177 | } |
| 173 | progress_reporter.clear()?; | 178 | let _ = progress_reporter.clear(); |
| 174 | Ok(()) | 179 | Ok(()) |
| 175 | } | 180 | } |
diff --git a/src/bin/ngit/main.rs b/src/bin/ngit/main.rs index 65f6bca..77ef955 100644 --- a/src/bin/ngit/main.rs +++ b/src/bin/ngit/main.rs | |||
| @@ -15,10 +15,6 @@ use ngit::{ | |||
| 15 | 15 | ||
| 16 | mod sub_commands; | 16 | mod sub_commands; |
| 17 | 17 | ||
| 18 | fn is_verbose() -> bool { | ||
| 19 | std::env::var("NGIT_VERBOSE").is_ok() || std::env::var("NGIT_TEST").is_ok() | ||
| 20 | } | ||
| 21 | |||
| 22 | #[tokio::main] | 18 | #[tokio::main] |
| 23 | async fn main() { | 19 | async fn main() { |
| 24 | let cli = Cli::parse(); | 20 | let cli = Cli::parse(); |
| @@ -29,7 +25,7 @@ async fn main() { | |||
| 29 | std::env::set_var("NGIT_INTERACTIVE_MODE", "1"); | 25 | std::env::set_var("NGIT_INTERACTIVE_MODE", "1"); |
| 30 | } | 26 | } |
| 31 | 27 | ||
| 32 | if cli.verbose || std::env::var("NGIT_TEST").is_ok() { | 28 | if cli.verbose || std::env::var("NGITTEST").is_ok() { |
| 33 | std::env::set_var("NGIT_VERBOSE", "1"); | 29 | std::env::set_var("NGIT_VERBOSE", "1"); |
| 34 | } | 30 | } |
| 35 | 31 | ||
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 | } |
diff --git a/src/bin/ngit/sub_commands/checkout.rs b/src/bin/ngit/sub_commands/checkout.rs index 6ded778..2fc9a09 100644 --- a/src/bin/ngit/sub_commands/checkout.rs +++ b/src/bin/ngit/sub_commands/checkout.rs | |||
| @@ -1,9 +1,11 @@ | |||
| 1 | use std::{ | 1 | use std::{ |
| 2 | collections::HashSet, | 2 | collections::HashSet, |
| 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::{ | 10 | client::{ |
| 9 | Params, get_all_proposal_patch_pr_pr_update_events_from_cache, | 11 | Params, get_all_proposal_patch_pr_pr_update_events_from_cache, |
| @@ -97,16 +99,55 @@ pub async fn launch(id: &str) -> Result<()> { | |||
| 97 | } | 99 | } |
| 98 | 100 | ||
| 99 | fn run_git_fetch(remote_name: &str) -> Result<()> { | 101 | fn run_git_fetch(remote_name: &str) -> Result<()> { |
| 100 | println!("fetching from {remote_name}..."); | 102 | let verbose = ngit::client::is_verbose(); |
| 101 | let exit_status = Command::new("git") | 103 | if verbose { |
| 104 | println!("fetching from {remote_name}..."); | ||
| 105 | } | ||
| 106 | |||
| 107 | let spinner = if verbose { | ||
| 108 | None | ||
| 109 | } else { | ||
| 110 | let pb = ProgressBar::new_spinner() | ||
| 111 | .with_style( | ||
| 112 | ProgressStyle::with_template("{spinner} {msg}") | ||
| 113 | .unwrap() | ||
| 114 | .tick_chars("⠁⠂⠄⡀⢀⠠⠐⠈"), | ||
| 115 | ) | ||
| 116 | .with_message(format!("Fetching from {remote_name}...")); | ||
| 117 | pb.enable_steady_tick(Duration::from_millis(100)); | ||
| 118 | Some(pb) | ||
| 119 | }; | ||
| 120 | |||
| 121 | let output = Command::new("git") | ||
| 102 | .args(["fetch", remote_name]) | 122 | .args(["fetch", remote_name]) |
| 103 | .stdout(Stdio::inherit()) | 123 | .stdout(if verbose { |
| 104 | .stderr(Stdio::inherit()) | 124 | Stdio::inherit() |
| 105 | .status() | 125 | } else { |
| 126 | Stdio::piped() | ||
| 127 | }) | ||
| 128 | .stderr(if verbose { | ||
| 129 | Stdio::inherit() | ||
| 130 | } else { | ||
| 131 | Stdio::piped() | ||
| 132 | }) | ||
| 133 | .output() | ||
| 106 | .context("failed to run git fetch")?; | 134 | .context("failed to run git fetch")?; |
| 107 | 135 | ||
| 108 | if !exit_status.success() { | 136 | if let Some(spinner) = spinner { |
| 109 | bail!("git fetch {remote_name} exited with error: {exit_status}"); | 137 | spinner.finish_and_clear(); |
| 138 | } | ||
| 139 | |||
| 140 | if !output.status.success() { | ||
| 141 | if !verbose { | ||
| 142 | let stderr = String::from_utf8_lossy(&output.stderr); | ||
| 143 | if !stderr.is_empty() { | ||
| 144 | eprintln!("{stderr}"); | ||
| 145 | } | ||
| 146 | } | ||
| 147 | bail!( | ||
| 148 | "git fetch {remote_name} exited with error: {}", | ||
| 149 | output.status | ||
| 150 | ); | ||
| 110 | } | 151 | } |
| 111 | Ok(()) | 152 | Ok(()) |
| 112 | } | 153 | } |
diff --git a/src/bin/ngit/sub_commands/list.rs b/src/bin/ngit/sub_commands/list.rs index 68a10cc..ff43bd9 100644 --- a/src/bin/ngit/sub_commands/list.rs +++ b/src/bin/ngit/sub_commands/list.rs | |||
| @@ -3,9 +3,11 @@ use std::{ | |||
| 3 | io::Write, | 3 | io::Write, |
| 4 | ops::Add, | 4 | ops::Add, |
| 5 | process::{Command, Stdio}, | 5 | process::{Command, Stdio}, |
| 6 | time::Duration, | ||
| 6 | }; | 7 | }; |
| 7 | 8 | ||
| 8 | use anyhow::{Context, Result, bail}; | 9 | use anyhow::{Context, Result, bail}; |
| 10 | use indicatif::{ProgressBar, ProgressStyle}; | ||
| 9 | use ngit::{ | 11 | use ngit::{ |
| 10 | client::{ | 12 | client::{ |
| 11 | Params, get_all_proposal_patch_pr_pr_update_events_from_cache, | 13 | Params, get_all_proposal_patch_pr_pr_update_events_from_cache, |
| @@ -39,16 +41,55 @@ use crate::{ | |||
| 39 | }; | 41 | }; |
| 40 | 42 | ||
| 41 | fn run_git_fetch(remote_name: &str) -> Result<()> { | 43 | fn run_git_fetch(remote_name: &str) -> Result<()> { |
| 42 | println!("fetching from {remote_name}..."); | 44 | let verbose = ngit::client::is_verbose(); |
| 43 | let exit_status = Command::new("git") | 45 | if verbose { |
| 46 | println!("fetching from {remote_name}..."); | ||
| 47 | } | ||
| 48 | |||
| 49 | let spinner = if verbose { | ||
| 50 | None | ||
| 51 | } else { | ||
| 52 | let pb = ProgressBar::new_spinner() | ||
| 53 | .with_style( | ||
| 54 | ProgressStyle::with_template("{spinner} {msg}") | ||
| 55 | .unwrap() | ||
| 56 | .tick_chars("⠁⠂⠄⡀⢀⠠⠐⠈"), | ||
| 57 | ) | ||
| 58 | .with_message(format!("Fetching from {remote_name}...")); | ||
| 59 | pb.enable_steady_tick(Duration::from_millis(100)); | ||
| 60 | Some(pb) | ||
| 61 | }; | ||
| 62 | |||
| 63 | let output = Command::new("git") | ||
| 44 | .args(["fetch", remote_name]) | 64 | .args(["fetch", remote_name]) |
| 45 | .stdout(Stdio::inherit()) | 65 | .stdout(if verbose { |
| 46 | .stderr(Stdio::inherit()) | 66 | Stdio::inherit() |
| 47 | .status() | 67 | } else { |
| 68 | Stdio::piped() | ||
| 69 | }) | ||
| 70 | .stderr(if verbose { | ||
| 71 | Stdio::inherit() | ||
| 72 | } else { | ||
| 73 | Stdio::piped() | ||
| 74 | }) | ||
| 75 | .output() | ||
| 48 | .context("failed to run git fetch")?; | 76 | .context("failed to run git fetch")?; |
| 49 | 77 | ||
| 50 | if !exit_status.success() { | 78 | if let Some(spinner) = spinner { |
| 51 | bail!("git fetch {remote_name} exited with error: {exit_status}"); | 79 | spinner.finish_and_clear(); |
| 80 | } | ||
| 81 | |||
| 82 | if !output.status.success() { | ||
| 83 | if !verbose { | ||
| 84 | let stderr = String::from_utf8_lossy(&output.stderr); | ||
| 85 | if !stderr.is_empty() { | ||
| 86 | eprintln!("{stderr}"); | ||
| 87 | } | ||
| 88 | } | ||
| 89 | bail!( | ||
| 90 | "git fetch {remote_name} exited with error: {}", | ||
| 91 | output.status | ||
| 92 | ); | ||
| 52 | } | 93 | } |
| 53 | Ok(()) | 94 | Ok(()) |
| 54 | } | 95 | } |
| @@ -297,10 +338,7 @@ fn show_proposal_details( | |||
| 297 | } | 338 | } |
| 298 | 339 | ||
| 299 | println!(); | 340 | println!(); |
| 300 | println!( | 341 | println!("To checkout: ngit checkout {}", proposal.id); |
| 301 | "To checkout: ngit checkout {}", | ||
| 302 | proposal.id | ||
| 303 | ); | ||
| 304 | println!("To apply: ngit apply {}", proposal.id); | 342 | println!("To apply: ngit apply {}", proposal.id); |
| 305 | 343 | ||
| 306 | Ok(()) | 344 | Ok(()) |