diff options
Diffstat (limited to 'src/bin/ngit')
| -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 |
4 files changed, 146 insertions, 30 deletions
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(()) |