diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/git_remote_helper.rs | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/git_remote_helper.rs b/src/git_remote_helper.rs index 8180175..12477da 100644 --- a/src/git_remote_helper.rs +++ b/src/git_remote_helper.rs | |||
| @@ -21,7 +21,7 @@ use client::{ | |||
| 21 | use git::RepoActions; | 21 | use git::RepoActions; |
| 22 | use git2::{Oid, Repository}; | 22 | use git2::{Oid, Repository}; |
| 23 | use nostr::nips::nip01::Coordinate; | 23 | use nostr::nips::nip01::Coordinate; |
| 24 | use nostr_sdk::{EventBuilder, PublicKey, Tag, Url}; | 24 | use nostr_sdk::{hashes::sha1::Hash as Sha1Hash, EventBuilder, PublicKey, Tag, Url}; |
| 25 | use nostr_signer::NostrSigner; | 25 | use nostr_signer::NostrSigner; |
| 26 | use repo_ref::RepoRef; | 26 | use repo_ref::RepoRef; |
| 27 | use repo_state::RepoState; | 27 | use repo_state::RepoState; |
| @@ -237,13 +237,22 @@ async fn list( | |||
| 237 | if let Some(remote_value) = remote_state.get(name) { | 237 | if let Some(remote_value) = remote_state.get(name) { |
| 238 | if value.ne(remote_value) { | 238 | if value.ne(remote_value) { |
| 239 | term.write_line( | 239 | term.write_line( |
| 240 | format!("WARNING: {url} {name} out of sync with nostr ").as_str(), | 240 | format!( |
| 241 | "WARNING: {url} {name} is {} nostr ", | ||
| 242 | if let Ok((ahead, behind)) = | ||
| 243 | get_ahead_behind(git_repo, value, remote_value) | ||
| 244 | { | ||
| 245 | format!("{} ahead {} behind", ahead.len(), behind.len()) | ||
| 246 | } else { | ||
| 247 | "out of sync with".to_string() | ||
| 248 | } | ||
| 249 | ) | ||
| 250 | .as_str(), | ||
| 241 | )?; | 251 | )?; |
| 242 | } | 252 | } |
| 243 | } else { | 253 | } else { |
| 244 | term.write_line( | 254 | term.write_line( |
| 245 | format!("WARNING: {url} is missing {name} which is tracked on nostr") | 255 | format!("WARNING: {url} {name} is missing but tracked on nostr").as_str(), |
| 246 | .as_str(), | ||
| 247 | )?; | 256 | )?; |
| 248 | } | 257 | } |
| 249 | } | 258 | } |
| @@ -319,6 +328,16 @@ fn list_from_remote( | |||
| 319 | Ok(state) | 328 | Ok(state) |
| 320 | } | 329 | } |
| 321 | 330 | ||
| 331 | fn get_ahead_behind( | ||
| 332 | git_repo: &Repo, | ||
| 333 | base_ref_or_oid: &str, | ||
| 334 | latest_ref_or_oid: &str, | ||
| 335 | ) -> Result<(Vec<Sha1Hash>, Vec<Sha1Hash>)> { | ||
| 336 | let base = git_repo.get_commit_or_tip_of_reference(base_ref_or_oid)?; | ||
| 337 | let latest = git_repo.get_commit_or_tip_of_reference(latest_ref_or_oid)?; | ||
| 338 | git_repo.get_commits_ahead_behind(&base, &latest) | ||
| 339 | } | ||
| 340 | |||
| 322 | fn fetch(git_repo: &Repository, repo_ref: &RepoRef, stdin: &Stdin, oid: &str) -> Result<()> { | 341 | fn fetch(git_repo: &Repository, repo_ref: &RepoRef, stdin: &Stdin, oid: &str) -> Result<()> { |
| 323 | let oids = get_oids_from_fetch_batch(stdin, oid)?; | 342 | let oids = get_oids_from_fetch_batch(stdin, oid)?; |
| 324 | 343 | ||