diff options
Diffstat (limited to 'src/lib/repo_ref.rs')
| -rw-r--r-- | src/lib/repo_ref.rs | 41 |
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))] |
| 16 | use crate::client::Client; | 16 | use crate::client::Client; |
| 17 | use crate::{ | 17 | use 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 | ||
| 436 | fn 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)] |
| 417 | pub struct RepoConfigYaml { | 454 | pub struct RepoConfigYaml { |
| 418 | pub identifier: Option<String>, | 455 | pub identifier: Option<String>, |