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.rs12
-rw-r--r--src/bin/ngit/sub_commands/init.rs10
2 files changed, 12 insertions, 10 deletions
diff --git a/src/bin/git_remote_nostr/main.rs b/src/bin/git_remote_nostr/main.rs
index 8e12d68..84327d7 100644
--- a/src/bin/git_remote_nostr/main.rs
+++ b/src/bin/git_remote_nostr/main.rs
@@ -9,7 +9,6 @@ use std::{
9 collections::HashSet, 9 collections::HashSet,
10 env, io, 10 env, io,
11 path::{Path, PathBuf}, 11 path::{Path, PathBuf},
12 str::FromStr,
13}; 12};
14 13
15use anyhow::{bail, Context, Result}; 14use anyhow::{bail, Context, Result};
@@ -28,7 +27,7 @@ mod utils;
28 27
29#[tokio::main] 28#[tokio::main]
30async fn main() -> Result<()> { 29async fn main() -> Result<()> {
31 let Some((decoded_nostr_url, git_repo)) = process_args()? else { 30 let Some((decoded_nostr_url, git_repo)) = process_args().await? else {
32 return Ok(()); 31 return Ok(());
33 }; 32 };
34 33
@@ -109,7 +108,7 @@ async fn main() -> Result<()> {
109 } 108 }
110} 109}
111 110
112fn process_args() -> Result<Option<(NostrUrlDecoded, Repo)>> { 111async fn process_args() -> Result<Option<(NostrUrlDecoded, Repo)>> {
113 let args = env::args(); 112 let args = env::args();
114 let args = args.skip(1).take(2).collect::<Vec<_>>(); 113 let args = args.skip(1).take(2).collect::<Vec<_>>();
115 114
@@ -135,13 +134,14 @@ fn process_args() -> Result<Option<(NostrUrlDecoded, Repo)>> {
135 return Ok(None); 134 return Ok(None);
136 }; 135 };
137 136
138 let decoded_nostr_url =
139 NostrUrlDecoded::from_str(nostr_remote_url).context("invalid nostr url")?;
140
141 let git_repo = Repo::from_path(&PathBuf::from( 137 let git_repo = Repo::from_path(&PathBuf::from(
142 std::env::var("GIT_DIR").context("git should set GIT_DIR when remote helper is called")?, 138 std::env::var("GIT_DIR").context("git should set GIT_DIR when remote helper is called")?,
143 ))?; 139 ))?;
144 140
141 let decoded_nostr_url = NostrUrlDecoded::parse_and_resolve(nostr_remote_url, &Some(&git_repo))
142 .await
143 .context("invalid nostr url")?;
144
145 Ok(Some((decoded_nostr_url, git_repo))) 145 Ok(Some((decoded_nostr_url, git_repo)))
146} 146}
147 147
diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs
index 6fc1ec4..c9c8873 100644
--- a/src/bin/ngit/sub_commands/init.rs
+++ b/src/bin/ngit/sub_commands/init.rs
@@ -1,4 +1,4 @@
1use std::{collections::HashMap, str::FromStr}; 1use std::collections::HashMap;
2 2
3use anyhow::{Context, Result}; 3use anyhow::{Context, Result};
4use console::Style; 4use console::Style;
@@ -442,7 +442,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
442 .map(std::string::ToString::to_string) 442 .map(std::string::ToString::to_string)
443 .collect::<Vec<String>>(); 443 .collect::<Vec<String>>();
444 444
445 prompt_to_set_nostr_url_as_origin(&repo_ref, &git_repo)?; 445 prompt_to_set_nostr_url_as_origin(&repo_ref, &git_repo).await?;
446 446
447 // TODO: if no state event exists and there is currently a remote called 447 // TODO: if no state event exists and there is currently a remote called
448 // "origin", automtically push rather than waiting for the next commit 448 // "origin", automtically push rather than waiting for the next commit
@@ -483,7 +483,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
483 Ok(()) 483 Ok(())
484} 484}
485 485
486fn prompt_to_set_nostr_url_as_origin(repo_ref: &RepoRef, git_repo: &Repo) -> Result<()> { 486async fn prompt_to_set_nostr_url_as_origin(repo_ref: &RepoRef, git_repo: &Repo) -> Result<()> {
487 println!( 487 println!(
488 "starting from your next commit, when you `git push` to a remote that uses your nostr url, it will store your repository state on nostr and update the state of the git server(s) you just listed." 488 "starting from your next commit, when you `git push` to a remote that uses your nostr url, it will store your repository state on nostr and update the state of the git server(s) you just listed."
489 ); 489 );
@@ -493,7 +493,9 @@ fn prompt_to_set_nostr_url_as_origin(repo_ref: &RepoRef, git_repo: &Repo) -> Res
493 493
494 if let Ok(origin_remote) = git_repo.git_repo.find_remote("origin") { 494 if let Ok(origin_remote) = git_repo.git_repo.find_remote("origin") {
495 if let Some(origin_url) = origin_remote.url() { 495 if let Some(origin_url) = origin_remote.url() {
496 if let Ok(nostr_url) = NostrUrlDecoded::from_str(origin_url) { 496 if let Ok(nostr_url) =
497 NostrUrlDecoded::parse_and_resolve(origin_url, &Some(git_repo)).await
498 {
497 if nostr_url.coordinate.identifier == repo_ref.identifier { 499 if nostr_url.coordinate.identifier == repo_ref.identifier {
498 if nostr_url.coordinate.public_key == repo_ref.trusted_maintainer { 500 if nostr_url.coordinate.public_key == repo_ref.trusted_maintainer {
499 return Ok(()); 501 return Ok(());