diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-05-23 11:56:58 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-05-23 12:43:30 +0100 |
| commit | 3f8539d640668888294e40fce384c9c5e0460f64 (patch) | |
| tree | 19a634b6057bded77b493e04400acd3d89cf4e8c /src | |
| parent | d1a88a390f0e15f42349099f37c6caedba813efd (diff) | |
fix(init): improve cli output
for git push, a wait longer to allow ngit-relays to create repo
Diffstat (limited to 'src')
| -rw-r--r-- | src/bin/ngit/sub_commands/init.rs | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs index 4b0f7b1..d3b3765 100644 --- a/src/bin/ngit/sub_commands/init.rs +++ b/src/bin/ngit/sub_commands/init.rs | |||
| @@ -7,7 +7,7 @@ use std::{ | |||
| 7 | }; | 7 | }; |
| 8 | 8 | ||
| 9 | use anyhow::{Context, Result, bail}; | 9 | use anyhow::{Context, Result, bail}; |
| 10 | use console::Style; | 10 | use console::{Style, Term}; |
| 11 | use dialoguer::theme::{ColorfulTheme, Theme}; | 11 | use dialoguer::theme::{ColorfulTheme, Theme}; |
| 12 | use ngit::{ | 12 | use ngit::{ |
| 13 | UrlWithoutSlash, | 13 | UrlWithoutSlash, |
| @@ -671,7 +671,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 671 | } | 671 | } |
| 672 | }; | 672 | }; |
| 673 | 673 | ||
| 674 | println!("publishing repostory reference..."); | 674 | println!("publishing repostory announcement to nostr..."); |
| 675 | 675 | ||
| 676 | let repo_ref = RepoRef { | 676 | let repo_ref = RepoRef { |
| 677 | identifier: identifier.clone(), | 677 | identifier: identifier.clone(), |
| @@ -725,11 +725,28 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 725 | } else { | 725 | } else { |
| 726 | git_repo.git_repo.remote("origin", &nostr_url)?; | 726 | git_repo.git_repo.remote("origin", &nostr_url)?; |
| 727 | } | 727 | } |
| 728 | thread::sleep(Duration::new(1, 0)); // wait for annoucment event to be receieved and processed by ngit-relays | 728 | println!("set remote origin to nostr url"); |
| 729 | 729 | ||
| 730 | if std::env::var("NGITTEST").is_err() { | 730 | if std::env::var("NGITTEST").is_err() { |
| 731 | // ignore during tests as git-remote-nostr isn't installed during ngit binary | 731 | // ignore during tests as git-remote-nostr isn't installed during ngit binary |
| 732 | // tests | 732 | // tests |
| 733 | |||
| 734 | if selected_ngit_relays.is_empty() { | ||
| 735 | println!("running `git push` to publish your repository data"); | ||
| 736 | } else { | ||
| 737 | let countdown_start = 5; | ||
| 738 | println!( | ||
| 739 | "waiting {countdown_start}s for ngit-relay servers to create your repo before we push your data" | ||
| 740 | ); | ||
| 741 | let term = Term::stdout(); | ||
| 742 | for i in (1..=countdown_start).rev() { | ||
| 743 | term.write_line(format!("\rrunning `git push` in {i}s").as_str())?; | ||
| 744 | thread::sleep(Duration::new(1, 0)); // Sleep for 1 second | ||
| 745 | term.clear_last_lines(1)?; | ||
| 746 | } | ||
| 747 | term.flush().unwrap(); // Ensure the output is flushed to the terminal | ||
| 748 | } | ||
| 749 | |||
| 733 | if let Err(err) = push_main_or_master_branch(&git_repo) { | 750 | if let Err(err) = push_main_or_master_branch(&git_repo) { |
| 734 | println!( | 751 | println!( |
| 735 | "your repository announcement was published to nostr but git push exited with an error: {err}" | 752 | "your repository announcement was published to nostr but git push exited with an error: {err}" |
| @@ -948,7 +965,9 @@ fn push_main_or_master_branch(git_repo: &Repo) -> Result<()> { | |||
| 948 | } | 965 | } |
| 949 | }; | 966 | }; |
| 950 | 967 | ||
| 951 | println!("set remote origin to nostr url and pushing {main_branch_name} branch."); | 968 | println!("========================================"); |
| 969 | println!(" GIT PUSH COMMAND "); | ||
| 970 | println!("========================================"); | ||
| 952 | 971 | ||
| 953 | let command = "git"; | 972 | let command = "git"; |
| 954 | let args = ["push", "origin", "-u", main_branch_name]; | 973 | let args = ["push", "origin", "-u", main_branch_name]; |
| @@ -964,6 +983,10 @@ fn push_main_or_master_branch(git_repo: &Repo) -> Result<()> { | |||
| 964 | // Wait for the process to finish | 983 | // Wait for the process to finish |
| 965 | let exit_status = child.wait().context("Failed to start git push process")?; | 984 | let exit_status = child.wait().context("Failed to start git push process")?; |
| 966 | 985 | ||
| 986 | println!("========================================"); | ||
| 987 | println!(" END OF GIT PUSH OUTPUT"); | ||
| 988 | println!("========================================"); | ||
| 989 | |||
| 967 | // Check the exit status | 990 | // Check the exit status |
| 968 | if exit_status.success() { | 991 | if exit_status.success() { |
| 969 | Ok(()) | 992 | Ok(()) |