upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/git_remote_nostr/main.rs72
1 files changed, 55 insertions, 17 deletions
diff --git a/src/bin/git_remote_nostr/main.rs b/src/bin/git_remote_nostr/main.rs
index e2738d2..f793a0c 100644
--- a/src/bin/git_remote_nostr/main.rs
+++ b/src/bin/git_remote_nostr/main.rs
@@ -15,7 +15,7 @@ use std::{
15use anyhow::{bail, Context, Result}; 15use anyhow::{bail, Context, Result};
16use client::{consolidate_fetch_reports, get_repo_ref_from_cache, Connect}; 16use client::{consolidate_fetch_reports, get_repo_ref_from_cache, Connect};
17use git::{nostr_url::NostrUrlDecoded, RepoActions}; 17use git::{nostr_url::NostrUrlDecoded, RepoActions};
18use ngit::{client, git}; 18use ngit::{client, git, login};
19use nostr::nips::nip01::Coordinate; 19use nostr::nips::nip01::Coordinate;
20use utils::read_line; 20use utils::read_line;
21 21
@@ -28,27 +28,42 @@ mod utils;
28 28
29#[tokio::main] 29#[tokio::main]
30async fn main() -> Result<()> { 30async fn main() -> Result<()> {
31 let args = env::args(); 31 let Some((decoded_nostr_url, git_repo)) = process_args()? else {
32 let args = args.skip(1).take(2).collect::<Vec<_>>();
33
34 let ([_, nostr_remote_url] | [nostr_remote_url]) = args.as_slice() else {
35 bail!("invalid arguments - no url");
36 };
37 if env::args().nth(1).as_deref() == Some("--version") {
38 const VERSION: &str = env!("CARGO_PKG_VERSION");
39 println!("v{VERSION}");
40 return Ok(()); 32 return Ok(());
41 } 33 };
42 34
43 let git_repo = Repo::from_path(&PathBuf::from(
44 std::env::var("GIT_DIR").context("git should set GIT_DIR when remote helper is called")?,
45 ))?;
46 let git_repo_path = git_repo.get_path()?; 35 let git_repo_path = git_repo.get_path()?;
47 36
48 let client = Client::default(); 37 let mut client = Client::default();
49 38
50 let decoded_nostr_url = 39 if git_repo
51 NostrUrlDecoded::from_str(nostr_remote_url).context("invalid nostr url")?; 40 .get_git_config_item("nostr.npub", None)
41 .is_ok_and(|x| x.is_some())
42 && (git_repo
43 .get_git_config_item("nostr.nsec", None)
44 .is_ok_and(|x| x.is_some())
45 || (git_repo
46 .get_git_config_item("nostr.bunker-uri", None)
47 .is_ok_and(|x| x.is_some())
48 && git_repo
49 .get_git_config_item("nostr.bunker-app-key", None)
50 .is_ok_and(|x| x.is_some())))
51 {
52 if let Ok((signer, _)) = login::launch(
53 &git_repo,
54 &None,
55 &None,
56 &None,
57 &None,
58 Some(&client),
59 false,
60 true,
61 )
62 .await
63 {
64 client.set_signer(signer).await;
65 };
66 }
52 67
53 fetching_with_report_for_helper(git_repo_path, &client, &decoded_nostr_url.coordinates).await?; 68 fetching_with_report_for_helper(git_repo_path, &client, &decoded_nostr_url.coordinates).await?;
54 69
@@ -115,6 +130,29 @@ async fn main() -> Result<()> {
115 } 130 }
116} 131}
117 132
133fn process_args() -> Result<Option<(NostrUrlDecoded, Repo)>> {
134 let args = env::args();
135 let args = args.skip(1).take(2).collect::<Vec<_>>();
136
137 let ([_, nostr_remote_url] | [nostr_remote_url]) = args.as_slice() else {
138 bail!("invalid arguments - no url");
139 };
140 let decoded_nostr_url =
141 NostrUrlDecoded::from_str(nostr_remote_url).context("invalid nostr url")?;
142
143 if env::args().nth(1).as_deref() == Some("--version") {
144 const VERSION: &str = env!("CARGO_PKG_VERSION");
145 println!("v{VERSION}");
146 return Ok(None);
147 }
148
149 let git_repo = Repo::from_path(&PathBuf::from(
150 std::env::var("GIT_DIR").context("git should set GIT_DIR when remote helper is called")?,
151 ))?;
152
153 Ok(Some((decoded_nostr_url, git_repo)))
154}
155
118async fn fetching_with_report_for_helper( 156async fn fetching_with_report_for_helper(
119 git_repo_path: &Path, 157 git_repo_path: &Path,
120 client: &Client, 158 client: &Client,