upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/bin/ngit/sub_commands/init.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-12-12 07:33:15 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2024-12-12 07:33:15 +0000
commit2b49a548169bf9bc3a3ef667a7e952e31e878bab (patch)
tree69e3fe439a0326729422a92488ee62420e28c9b7 /src/bin/ngit/sub_commands/init.rs
parentd8f4f7641312bff32f772cbc070b3f99ced0c8fe (diff)
parent2c6e281c1643593cd079936924dc1d4e65c54ed6 (diff)
feat(NostrUrlDecode): add nip05 address support
enable nostr git url format alongside and format Merge branch 'pr/nip05-lez(ff1845c0)'
Diffstat (limited to 'src/bin/ngit/sub_commands/init.rs')
-rw-r--r--src/bin/ngit/sub_commands/init.rs16
1 files changed, 9 insertions, 7 deletions
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}