From 29f61ffdf155ea88b8d9aec23d28cf70baba577e Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Tue, 5 Aug 2025 11:38:09 +0100 Subject: feat(send): custom ref for PR clone url allow specifying ref for pushing PR to custom clone url --- src/bin/git_remote_nostr/push.rs | 1 + src/bin/ngit/sub_commands/send.rs | 14 +++++++++++++- src/lib/push.rs | 8 +++++++- 3 files changed, 21 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs index 4552b91..f98e792 100644 --- a/src/bin/git_remote_nostr/push.rs +++ b/src/bin/git_remote_nostr/push.rs @@ -482,6 +482,7 @@ async fn generate_patches_or_pr_event_or_pr_updates( root_proposal, &None, &repo_grasp_clone_urls, + None, signer, term, ) diff --git a/src/bin/ngit/sub_commands/send.rs b/src/bin/ngit/sub_commands/send.rs index 69ad1e6..609812b 100644 --- a/src/bin/ngit/sub_commands/send.rs +++ b/src/bin/ngit/sub_commands/send.rs @@ -208,6 +208,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs, no_fetch: bool) -> Re } let mut to_try = repo_grasp_clone_urls.clone(); let mut tried = vec![]; + let mut git_ref = None; loop { let (events, _server_responses) = push_refs_and_generate_pr_or_pr_update_event( &git_repo, @@ -217,6 +218,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs, no_fetch: bool) -> Re root_proposal.as_ref(), &cover_letter_title_description, &repo_grasp_clone_urls, + git_ref.clone(), &signer, &console::Term::stdout(), ) @@ -235,7 +237,17 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs, no_fetch: bool) -> Re .clone(); if CloneUrl::from_str(&clone_url).is_ok() { to_try.push(clone_url); - // TODO customise ref to push + let mut git_ref_or_branch_name = Interactor::default() + .input( + PromptInputParms::default() + .with_prompt("ref / branch name") + .with_default(git_ref.unwrap_or("refs/nostr/".to_string())), + )? + .clone(); + if !git_ref_or_branch_name.starts_with("refs/") { + git_ref_or_branch_name = format!("refs/heads/{git_ref_or_branch_name}"); + } + git_ref = Some(git_ref_or_branch_name); } else { println!("invalid clone url"); } diff --git a/src/lib/push.rs b/src/lib/push.rs index 4c2d8f1..c202397 100644 --- a/src/lib/push.rs +++ b/src/lib/push.rs @@ -330,6 +330,7 @@ pub async fn push_refs_and_generate_pr_or_pr_update_event( root_proposal: Option<&Event>, title_description_overide: &Option<(String, String)>, servers: &[String], + git_ref: Option, signer: &Arc, term: &Term, ) -> Result<(Option>, Vec<(String, Result<()>)>)> { @@ -352,7 +353,12 @@ pub async fn push_refs_and_generate_pr_or_pr_update_event( )? }; - let refspec = format!("{}:refs/nostr/{}", tip, draft_pr_event.id()); + let git_ref_used = git_ref + .clone() + .unwrap_or("refs/nostr/".to_string()) + .replace("", &draft_pr_event.id().to_string()); + + let refspec = format!("{tip}:{git_ref_used}"); if let Err(error) = push_to_remote_url(git_repo, clone_url, &[refspec], term) { term.write_line( -- cgit v1.2.3