upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/git_remote_helper.rs27
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::{
21use git::RepoActions; 21use git::RepoActions;
22use git2::{Oid, Repository}; 22use git2::{Oid, Repository};
23use nostr::nips::nip01::Coordinate; 23use nostr::nips::nip01::Coordinate;
24use nostr_sdk::{EventBuilder, PublicKey, Tag, Url}; 24use nostr_sdk::{hashes::sha1::Hash as Sha1Hash, EventBuilder, PublicKey, Tag, Url};
25use nostr_signer::NostrSigner; 25use nostr_signer::NostrSigner;
26use repo_ref::RepoRef; 26use repo_ref::RepoRef;
27use repo_state::RepoState; 27use 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
331fn 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
322fn fetch(git_repo: &Repository, repo_ref: &RepoRef, stdin: &Stdin, oid: &str) -> Result<()> { 341fn 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