diff options
Diffstat (limited to 'src/git_remote_helper.rs')
| -rw-r--r-- | src/git_remote_helper.rs | 33 |
1 files changed, 5 insertions, 28 deletions
diff --git a/src/git_remote_helper.rs b/src/git_remote_helper.rs index 1c1688d..6dc00cb 100644 --- a/src/git_remote_helper.rs +++ b/src/git_remote_helper.rs | |||
| @@ -9,14 +9,15 @@ use std::{ | |||
| 9 | collections::{HashMap, HashSet}, | 9 | collections::{HashMap, HashSet}, |
| 10 | env, | 10 | env, |
| 11 | io::{self, Stdin}, | 11 | io::{self, Stdin}, |
| 12 | path::{Path, PathBuf}, | 12 | 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; | ||
| 17 | use client::{ | 19 | use client::{ |
| 18 | consolidate_fetch_reports, get_repo_ref_from_cache, get_state_from_cache, sign_event, Connect, | 20 | fetching_with_report, get_repo_ref_from_cache, get_state_from_cache, sign_event, STATE_KIND, |
| 19 | STATE_KIND, | ||
| 20 | }; | 21 | }; |
| 21 | use git::RepoActions; | 22 | use git::RepoActions; |
| 22 | use git2::{Oid, Repository}; | 23 | use git2::{Oid, Repository}; |
| @@ -71,7 +72,7 @@ async fn main() -> Result<()> { | |||
| 71 | let repo_coordinates = | 72 | let repo_coordinates = |
| 72 | nostr_git_url_to_repo_coordinates(nostr_remote_url).context("invalid nostr url")?; | 73 | nostr_git_url_to_repo_coordinates(nostr_remote_url).context("invalid nostr url")?; |
| 73 | 74 | ||
| 74 | fetching_with_report_for_helper(git_repo_path, &client, &repo_coordinates).await?; | 75 | fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; |
| 75 | 76 | ||
| 76 | let repo_ref = get_repo_ref_from_cache(git_repo_path, &repo_coordinates).await?; | 77 | let repo_ref = get_repo_ref_from_cache(git_repo_path, &repo_coordinates).await?; |
| 77 | 78 | ||
| @@ -189,30 +190,6 @@ fn nostr_git_url_to_repo_coordinates(url: &str) -> Result<HashSet<Coordinate>> { | |||
| 189 | ); | 190 | ); |
| 190 | } | 191 | } |
| 191 | 192 | ||
| 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("fetching from nostr...")?; | ||
| 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("no updates on nostr")?; | ||
| 210 | } else { | ||
| 211 | term.write_line(&format!("nostr updates: {report}"))?; | ||
| 212 | } | ||
| 213 | Ok(()) | ||
| 214 | } | ||
| 215 | |||
| 216 | async fn list(git_repo: &Repo, repo_ref: &RepoRef, for_push: bool) -> Result<()> { | 193 | async fn list(git_repo: &Repo, repo_ref: &RepoRef, for_push: bool) -> Result<()> { |
| 217 | if let Ok(repo_state) = get_state_from_cache(git_repo.get_path()?, repo_ref).await { | 194 | if let Ok(repo_state) = get_state_from_cache(git_repo.get_path()?, repo_ref).await { |
| 218 | for (name, value) in &repo_state.state { | 195 | for (name, value) in &repo_state.state { |