diff options
Diffstat (limited to 'src/bin/ngit/sub_commands/checkout.rs')
| -rw-r--r-- | src/bin/ngit/sub_commands/checkout.rs | 55 |
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 @@ | |||
| 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 | } |