upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/lib/repo_ref.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-12-05 12:15:27 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2024-12-05 12:15:27 +0000
commit91bee7f92fa540f7883519ee9db125fc6a0cf830 (patch)
treef85a51c6aa4948a78ca1c295d17df327415df423 /src/lib/repo_ref.rs
parentc6fef5613fc64037e591a6515c025d5ed559915c (diff)
fix(ngit): save new nostr url as git remote
when nostr address is unknown and user is prompted to enter it, ask the user to save it as a git remote.
Diffstat (limited to 'src/lib/repo_ref.rs')
-rw-r--r--src/lib/repo_ref.rs41
1 files changed, 39 insertions, 2 deletions
diff --git a/src/lib/repo_ref.rs b/src/lib/repo_ref.rs
index 89aec17..b21a4e9 100644
--- a/src/lib/repo_ref.rs
+++ b/src/lib/repo_ref.rs
@@ -15,8 +15,10 @@ use serde::{Deserialize, Serialize};
15#[cfg(not(test))] 15#[cfg(not(test))]
16use crate::client::Client; 16use crate::client::Client;
17use crate::{ 17use crate::{
18 cli_interactor::{Interactor, InteractorPrompt, PromptChoiceParms, PromptInputParms}, 18 cli_interactor::{
19 client::{consolidate_fetch_reports, sign_event, Connect}, 19 Interactor, InteractorPrompt, PromptChoiceParms, PromptConfirmParms, PromptInputParms,
20 },
21 client::{consolidate_fetch_reports, get_repo_ref_from_cache, sign_event, Connect},
20 git::{nostr_url::NostrUrlDecoded, Repo, RepoActions}, 22 git::{nostr_url::NostrUrlDecoded, Repo, RepoActions},
21 login::user::get_user_details, 23 login::user::get_user_details,
22}; 24};
@@ -410,9 +412,44 @@ async fn get_repo_coordinate_from_user_prompt(
410 } 412 }
411 } 413 }
412 }; 414 };
415 let repo_ref = get_repo_ref_from_cache(Some(git_repo_path), &coordinate).await?;
416
417 if Interactor::default().confirm(
418 PromptConfirmParms::default()
419 .with_default(true)
420 .with_prompt("set git remote \"origin\" to nostr repository url?"),
421 )? {
422 set_or_create_git_remote_with_nostr_url("origin", &repo_ref, git_repo)?;
423 } else if Interactor::default().confirm(
424 PromptConfirmParms::default()
425 .with_default(true)
426 .with_prompt("set up new git remote for the nostr repository?"),
427 )? {
428 let name =
429 Interactor::default().input(PromptInputParms::default().with_prompt("remote name"))?;
430 set_or_create_git_remote_with_nostr_url(&name, &repo_ref, git_repo)?;
431 }
432 git_repo.save_git_config_item("nostr.repo", &coordinate.to_bech32()?, false)?;
413 Ok(coordinate) 433 Ok(coordinate)
414} 434}
415 435
436fn set_or_create_git_remote_with_nostr_url(
437 name: &str,
438 repo_ref: &RepoRef,
439 git_repo: &Repo,
440) -> Result<()> {
441 if git_repo
442 .git_repo
443 .remote_set_url(name, &repo_ref.to_nostr_git_url())
444 .is_err()
445 {
446 let url = repo_ref.to_nostr_git_url();
447 git_repo.git_repo.remote(name, &url)?;
448 eprintln!("set git remote \"{name}\" to {url}");
449 }
450 Ok(())
451}
452
416#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq, Eq)] 453#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq, Eq)]
417pub struct RepoConfigYaml { 454pub struct RepoConfigYaml {
418 pub identifier: Option<String>, 455 pub identifier: Option<String>,