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.rs16
2 files changed, 15 insertions, 13 deletions
diff --git a/src/bin/git_remote_nostr/main.rs b/src/bin/git_remote_nostr/main.rs
index 5f9f712..1a21341 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
@@ -118,7 +117,7 @@ async fn main() -> Result<()> {
118 } 117 }
119} 118}
120 119
121fn process_args() -> Result<Option<(NostrUrlDecoded, Repo)>> { 120async fn process_args() -> Result<Option<(NostrUrlDecoded, Repo)>> {
122 let args = env::args(); 121 let args = env::args();
123 let args = args.skip(1).take(2).collect::<Vec<_>>(); 122 let args = args.skip(1).take(2).collect::<Vec<_>>();
124 123
@@ -144,13 +143,14 @@ fn process_args() -> Result<Option<(NostrUrlDecoded, Repo)>> {
144 return Ok(None); 143 return Ok(None);
145 }; 144 };
146 145
147 let decoded_nostr_url =
148 NostrUrlDecoded::from_str(nostr_remote_url).context("invalid nostr url")?;
149
150 let git_repo = Repo::from_path(&PathBuf::from( 146 let git_repo = Repo::from_path(&PathBuf::from(
151 std::env::var("GIT_DIR").context("git should set GIT_DIR when remote helper is called")?, 147 std::env::var("GIT_DIR").context("git should set GIT_DIR when remote helper is called")?,
152 ))?; 148 ))?;
153 149
150 let decoded_nostr_url = NostrUrlDecoded::parse_and_resolve(nostr_remote_url, &Some(&git_repo))
151 .await
152 .context("invalid nostr url")?;
153
154 Ok(Some((decoded_nostr_url, git_repo))) 154 Ok(Some((decoded_nostr_url, git_repo)))
155} 155}
156 156
diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs
index 7ed98f5..1695e4c 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;
@@ -443,7 +443,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
443 .map(std::string::ToString::to_string) 443 .map(std::string::ToString::to_string)
444 .collect::<Vec<String>>(); 444 .collect::<Vec<String>>();
445 445
446 prompt_to_set_nostr_url_as_origin(&repo_ref, &git_repo)?; 446 prompt_to_set_nostr_url_as_origin(&repo_ref, &git_repo).await?;
447 447
448 // TODO: if no state event exists and there is currently a remote called 448 // TODO: if no state event exists and there is currently a remote called
449 // "origin", automtically push rather than waiting for the next commit 449 // "origin", automtically push rather than waiting for the next commit
@@ -484,7 +484,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
484 Ok(()) 484 Ok(())
485} 485}
486 486
487fn prompt_to_set_nostr_url_as_origin(repo_ref: &RepoRef, git_repo: &Repo) -> Result<()> { 487async fn prompt_to_set_nostr_url_as_origin(repo_ref: &RepoRef, git_repo: &Repo) -> Result<()> {
488 println!( 488 println!(
489 "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 "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."
490 ); 490 );
@@ -494,7 +494,9 @@ fn prompt_to_set_nostr_url_as_origin(repo_ref: &RepoRef, git_repo: &Repo) -> Res
494 494
495 if let Ok(origin_remote) = git_repo.git_repo.find_remote("origin") { 495 if let Ok(origin_remote) = git_repo.git_repo.find_remote("origin") {
496 if let Some(origin_url) = origin_remote.url() { 496 if let Some(origin_url) = origin_remote.url() {
497 if let Ok(nostr_url) = NostrUrlDecoded::from_str(origin_url) { 497 if let Ok(nostr_url) =
498 NostrUrlDecoded::parse_and_resolve(origin_url, &Some(git_repo)).await
499 {
498 if nostr_url.coordinate.identifier == repo_ref.identifier { 500 if nostr_url.coordinate.identifier == repo_ref.identifier {
499 if nostr_url.coordinate.public_key == repo_ref.trusted_maintainer { 501 if nostr_url.coordinate.public_key == repo_ref.trusted_maintainer {
500 return Ok(()); 502 return Ok(());
@@ -521,7 +523,7 @@ fn prompt_to_set_nostr_url_as_origin(repo_ref: &RepoRef, git_repo: &Repo) -> Res
521 } 523 }
522 } 524 }
523 println!("contributors can clone your repository by installing ngit and using this clone url:"); 525 println!("contributors can clone your repository by installing ngit and using this clone url:");
524 println!("{}", repo_ref.to_nostr_git_url()); 526 println!("{}", repo_ref.to_nostr_git_url(&Some(git_repo)));
525 527
526 Ok(()) 528 Ok(())
527} 529}
@@ -534,7 +536,7 @@ fn ask_to_set_origin_remote(repo_ref: &RepoRef, git_repo: &Repo) -> Result<()> {
534 )? { 536 )? {
535 git_repo 537 git_repo
536 .git_repo 538 .git_repo
537 .remote_set_url("origin", &repo_ref.to_nostr_git_url())?; 539 .remote_set_url("origin", &repo_ref.to_nostr_git_url(&Some(git_repo)))?;
538 } 540 }
539 Ok(()) 541 Ok(())
540} 542}
@@ -547,7 +549,7 @@ fn ask_to_create_new_origin_remote(repo_ref: &RepoRef, git_repo: &Repo) -> Resul
547 )? { 549 )? {
548 git_repo 550 git_repo
549 .git_repo 551 .git_repo
550 .remote("origin", &repo_ref.to_nostr_git_url())?; 552 .remote("origin", &repo_ref.to_nostr_git_url(&Some(git_repo)))?;
551 } 553 }
552 Ok(()) 554 Ok(())
553} 555}