upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/bin/ngit/sub_commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/ngit/sub_commands')
-rw-r--r--src/bin/ngit/sub_commands/apply.rs55
-rw-r--r--src/bin/ngit/sub_commands/checkout.rs55
-rw-r--r--src/bin/ngit/sub_commands/list.rs60
3 files changed, 145 insertions, 25 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 @@
1use std::{ 1use std::{
2 io::Write, 2 io::Write,
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::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
20fn run_git_fetch(remote_name: &str) -> Result<()> { 22fn 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 @@
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}
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
8use anyhow::{Context, Result, bail}; 9use anyhow::{Context, Result, bail};
10use indicatif::{ProgressBar, ProgressStyle};
9use ngit::{ 11use 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
41fn run_git_fetch(remote_name: &str) -> Result<()> { 43fn 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(())