diff options
| -rw-r--r-- | src/git_remote_helper.rs | 33 | ||||
| -rw-r--r-- | tests/git_remote_helper.rs | 2 |
2 files changed, 29 insertions, 6 deletions
diff --git a/src/git_remote_helper.rs b/src/git_remote_helper.rs index 6dc00cb..f8a9db4 100644 --- a/src/git_remote_helper.rs +++ b/src/git_remote_helper.rs | |||
| @@ -9,15 +9,14 @@ use std::{ | |||
| 9 | collections::{HashMap, HashSet}, | 9 | collections::{HashMap, HashSet}, |
| 10 | env, | 10 | env, |
| 11 | io::{self, Stdin}, | 11 | io::{self, Stdin}, |
| 12 | path::PathBuf, | 12 | path::{Path, PathBuf}, |
| 13 | }; | 13 | }; |
| 14 | 14 | ||
| 15 | use anyhow::{bail, Context, Result}; | 15 | use anyhow::{bail, Context, Result}; |
| 16 | use auth_git2::GitAuthenticator; | 16 | use auth_git2::GitAuthenticator; |
| 17 | #[cfg(not(test))] | ||
| 18 | use client::Connect; | ||
| 19 | use client::{ | 17 | use client::{ |
| 20 | fetching_with_report, get_repo_ref_from_cache, get_state_from_cache, sign_event, STATE_KIND, | 18 | consolidate_fetch_reports, get_repo_ref_from_cache, get_state_from_cache, sign_event, Connect, |
| 19 | STATE_KIND, | ||
| 21 | }; | 20 | }; |
| 22 | use git::RepoActions; | 21 | use git::RepoActions; |
| 23 | use git2::{Oid, Repository}; | 22 | use git2::{Oid, Repository}; |
| @@ -72,7 +71,7 @@ async fn main() -> Result<()> { | |||
| 72 | let repo_coordinates = | 71 | let repo_coordinates = |
| 73 | nostr_git_url_to_repo_coordinates(nostr_remote_url).context("invalid nostr url")?; | 72 | nostr_git_url_to_repo_coordinates(nostr_remote_url).context("invalid nostr url")?; |
| 74 | 73 | ||
| 75 | fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; | 74 | fetching_with_report_for_helper(git_repo_path, &client, &repo_coordinates).await?; |
| 76 | 75 | ||
| 77 | let repo_ref = get_repo_ref_from_cache(git_repo_path, &repo_coordinates).await?; | 76 | let repo_ref = get_repo_ref_from_cache(git_repo_path, &repo_coordinates).await?; |
| 78 | 77 | ||
| @@ -190,6 +189,30 @@ fn nostr_git_url_to_repo_coordinates(url: &str) -> Result<HashSet<Coordinate>> { | |||
| 190 | ); | 189 | ); |
| 191 | } | 190 | } |
| 192 | 191 | ||
| 192 | async fn fetching_with_report_for_helper( | ||
| 193 | git_repo_path: &Path, | ||
| 194 | #[cfg(test)] client: &crate::client::MockConnect, | ||
| 195 | #[cfg(not(test))] client: &Client, | ||
| 196 | repo_coordinates: &HashSet<Coordinate>, | ||
| 197 | ) -> Result<()> { | ||
| 198 | let term = console::Term::stderr(); | ||
| 199 | term.write_line("nostr: fetching...")?; | ||
| 200 | let (relay_reports, progress_reporter) = client | ||
| 201 | .fetch_all(git_repo_path, repo_coordinates, &HashSet::new()) | ||
| 202 | .await?; | ||
| 203 | if !relay_reports.iter().any(std::result::Result::is_err) { | ||
| 204 | let _ = progress_reporter.clear(); | ||
| 205 | term.clear_last_lines(1)?; | ||
| 206 | } | ||
| 207 | let report = consolidate_fetch_reports(relay_reports); | ||
| 208 | if report.to_string().is_empty() { | ||
| 209 | term.write_line("nostr: no updates")?; | ||
| 210 | } else { | ||
| 211 | term.write_line(&format!("nostr updates: {report}"))?; | ||
| 212 | } | ||
| 213 | Ok(()) | ||
| 214 | } | ||
| 215 | |||
| 193 | async fn list(git_repo: &Repo, repo_ref: &RepoRef, for_push: bool) -> Result<()> { | 216 | async fn list(git_repo: &Repo, repo_ref: &RepoRef, for_push: bool) -> Result<()> { |
| 194 | if let Ok(repo_state) = get_state_from_cache(git_repo.get_path()?, repo_ref).await { | 217 | if let Ok(repo_state) = get_state_from_cache(git_repo.get_path()?, repo_ref).await { |
| 195 | for (name, value) in &repo_state.state { | 218 | for (name, value) in &repo_state.state { |
diff --git a/tests/git_remote_helper.rs b/tests/git_remote_helper.rs index fda393f..b63345c 100644 --- a/tests/git_remote_helper.rs +++ b/tests/git_remote_helper.rs | |||
| @@ -58,7 +58,7 @@ fn cli_tester(git_repo: &GitTestRepo) -> CliTester { | |||
| 58 | 58 | ||
| 59 | fn cli_tester_after_fetch(git_repo: &GitTestRepo) -> Result<CliTester> { | 59 | fn cli_tester_after_fetch(git_repo: &GitTestRepo) -> Result<CliTester> { |
| 60 | let mut p = cli_tester(git_repo); | 60 | let mut p = cli_tester(git_repo); |
| 61 | p.expect("fetching updates...\r\n")?; | 61 | p.expect("nostr: fetching...\r\n")?; |
| 62 | p.expect_eventually("updates")?; // some updates | 62 | p.expect_eventually("updates")?; // some updates |
| 63 | p.expect_eventually("\r\n")?; | 63 | p.expect_eventually("\r\n")?; |
| 64 | Ok(p) | 64 | Ok(p) |