upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/bin/ngit/sub_commands/checkout.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2026-02-13 10:51:25 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2026-02-13 10:51:25 +0000
commit40b439ae4d69b858274be51dd5af513c3b4f46f0 (patch)
tree64beb8589b8a2da5aee7aecf8dc9564e21d676d0 /src/bin/ngit/sub_commands/checkout.rs
parentcfd8cc19b6a81ad78bc30d5b21cefe21d574d09e (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/checkout.rs')
-rw-r--r--src/bin/ngit/sub_commands/checkout.rs55
1 files changed, 48 insertions, 7 deletions
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 @@
1use std::{ 1use std::{
2 collections::HashSet, 2 collections::HashSet,
3 process::{Command, Stdio}, 3 process::{Command, Stdio},
4 time::Duration,
4}; 5};
5 6
6use anyhow::{Context, Result, bail}; 7use anyhow::{Context, Result, bail};
8use indicatif::{ProgressBar, ProgressStyle};
7use ngit::{ 9use 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
99fn run_git_fetch(remote_name: &str) -> Result<()> { 101fn 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}