From b67376ff54abeab31422921ba5f4883d5d3dccdb Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Tue, 23 Jul 2024 16:36:06 +0100 Subject: feat(list): unique proposal branch names to prevent accidental name conflicts. also moved to prs/* namespace `pull` and `push` integration tests are intermitantly failing to end at least for `push` they work when run individually but not when run together --- src/sub_commands/list.rs | 39 +++++++++++++++++++++------------------ src/sub_commands/pull.rs | 3 ++- src/sub_commands/push.rs | 8 ++++++-- src/sub_commands/send.rs | 15 +++++++++++++++ 4 files changed, 44 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/sub_commands/list.rs b/src/sub_commands/list.rs index 2ae4cfb..cc7ac6f 100644 --- a/src/sub_commands/list.rs +++ b/src/sub_commands/list.rs @@ -263,11 +263,11 @@ pub async fn launch() -> Result<()> { .get_local_branch_names() .context("gitlib2 will not show a list of local branch names")? .iter() - .any(|n| n.eq(&cover_letter.branch_name)); + .any(|n| n.eq(&cover_letter.get_branch_name().unwrap())); let checked_out_proposal_branch = git_repo .get_checked_out_branch_name()? - .eq(&cover_letter.branch_name); + .eq(&cover_letter.get_branch_name()?); let proposal_base_commit = str_to_sha1(&tag_value( most_recent_proposal_patch_chain.last().context( @@ -329,14 +329,14 @@ pub async fn launch() -> Result<()> { check_clean(&git_repo)?; let _ = git_repo .apply_patch_chain( - &cover_letter.branch_name, + &cover_letter.get_branch_name()?, most_recent_proposal_patch_chain, ) .context("cannot apply patch chain")?; println!( "checked out proposal as '{}' branch", - cover_letter.branch_name + cover_letter.get_branch_name()? ); Ok(()) } @@ -349,7 +349,7 @@ pub async fn launch() -> Result<()> { }; } - let local_branch_tip = git_repo.get_tip_of_branch(&cover_letter.branch_name)?; + let local_branch_tip = git_repo.get_tip_of_branch(&cover_letter.get_branch_name()?)?; // up-to-date if proposal_tip.eq(&local_branch_tip) { @@ -384,10 +384,10 @@ pub async fn launch() -> Result<()> { )? { 0 => { check_clean(&git_repo)?; - git_repo.checkout(&cover_letter.branch_name)?; + git_repo.checkout(&cover_letter.get_branch_name()?)?; println!( "checked out proposal as '{}' branch", - cover_letter.branch_name + cover_letter.get_branch_name()? ); Ok(()) } @@ -421,10 +421,10 @@ pub async fn launch() -> Result<()> { )? { 0 => { check_clean(&git_repo)?; - git_repo.checkout(&cover_letter.branch_name)?; + git_repo.checkout(&cover_letter.get_branch_name()?)?; let _ = git_repo .apply_patch_chain( - &cover_letter.branch_name, + &cover_letter.get_branch_name()?, most_recent_proposal_patch_chain, ) .context("cannot apply patch chain")?; @@ -474,14 +474,14 @@ pub async fn launch() -> Result<()> { 0 => { check_clean(&git_repo)?; git_repo.create_branch_at_commit( - &cover_letter.branch_name, + &cover_letter.get_branch_name()?, &proposal_base_commit.to_string(), )?; - git_repo.checkout(&cover_letter.branch_name)?; + git_repo.checkout(&cover_letter.get_branch_name()?)?; let chain_length = most_recent_proposal_patch_chain.len(); let _ = git_repo .apply_patch_chain( - &cover_letter.branch_name, + &cover_letter.get_branch_name()?, most_recent_proposal_patch_chain, ) .context("cannot apply patch chain")?; @@ -496,7 +496,7 @@ pub async fn launch() -> Result<()> { } 1 => { check_clean(&git_repo)?; - git_repo.checkout(&cover_letter.branch_name)?; + git_repo.checkout(&cover_letter.get_branch_name()?)?; println!( "checked out old proposal in existing branch ({} ahead {} behind '{main_branch_name}')", local_ahead_of_main.len(), @@ -537,7 +537,7 @@ pub async fn launch() -> Result<()> { ]), )? { 0 => { - git_repo.checkout(&cover_letter.branch_name)?; + git_repo.checkout(&cover_letter.get_branch_name()?)?; println!( "checked out proposal branch with {} unpublished commits ({} ahead {} behind '{main_branch_name}')", local_ahead_of_proposal.len(), @@ -604,7 +604,7 @@ pub async fn launch() -> Result<()> { )? { 0 => { check_clean(&git_repo)?; - git_repo.checkout(&cover_letter.branch_name)?; + git_repo.checkout(&cover_letter.get_branch_name()?)?; println!( "checked out old proposal in existing branch ({} ahead {} behind '{main_branch_name}')", local_ahead_of_main.len(), @@ -615,15 +615,18 @@ pub async fn launch() -> Result<()> { 1 => { check_clean(&git_repo)?; git_repo.create_branch_at_commit( - &cover_letter.branch_name, + &cover_letter.get_branch_name()?, &proposal_base_commit.to_string(), )?; let chain_length = most_recent_proposal_patch_chain.len(); let _ = git_repo - .apply_patch_chain(&cover_letter.branch_name, most_recent_proposal_patch_chain) + .apply_patch_chain( + &cover_letter.get_branch_name()?, + most_recent_proposal_patch_chain, + ) .context("cannot apply patch chain")?; - git_repo.checkout(&cover_letter.branch_name)?; + git_repo.checkout(&cover_letter.get_branch_name()?)?; println!( "checked out latest version of proposal ({} ahead {} behind '{main_branch_name}'), replacing unpublished version ({} ahead {} behind '{main_branch_name}')", chain_length, diff --git a/src/sub_commands/pull.rs b/src/sub_commands/pull.rs index dfa6f89..e33a744 100644 --- a/src/sub_commands/pull.rs +++ b/src/sub_commands/pull.rs @@ -50,7 +50,8 @@ pub async fn launch() -> Result<()> { .await? .iter() .find(|e| { - event_to_cover_letter(e).is_ok_and(|cl| cl.branch_name.eq(&branch_name)) + event_to_cover_letter(e) + .is_ok_and(|cl| cl.get_branch_name().is_ok_and(|s| s.eq(&branch_name))) && !event_is_revision_root(e) }) .context("cannot find proposal that matches the current branch name")? diff --git a/src/sub_commands/push.rs b/src/sub_commands/push.rs index d05158f..9af8b40 100644 --- a/src/sub_commands/push.rs +++ b/src/sub_commands/push.rs @@ -16,7 +16,7 @@ use crate::{ get_most_recent_patch_with_ancestors, get_proposals_and_revisions_from_cache, tag_value, }, - send::{event_to_cover_letter, generate_patch_event, send_events}, + send::{event_is_revision_root, event_to_cover_letter, generate_patch_event, send_events}, }, Cli, }; @@ -66,7 +66,11 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { get_proposals_and_revisions_from_cache(git_repo_path, repo_ref.coordinates()) .await? .iter() - .find(|e| event_to_cover_letter(e).is_ok_and(|cl| cl.branch_name.eq(&branch_name))) + .find(|e| { + event_to_cover_letter(e) + .is_ok_and(|cl| cl.get_branch_name().is_ok_and(|s| s.eq(&branch_name))) + && !event_is_revision_root(e) + }) .context("cannot find proposal that matches the current branch name")? .clone(); diff --git a/src/sub_commands/send.rs b/src/sub_commands/send.rs index 33ce104..6b9dd58 100644 --- a/src/sub_commands/send.rs +++ b/src/sub_commands/send.rs @@ -769,8 +769,22 @@ pub struct CoverLetter { pub title: String, pub description: String, pub branch_name: String, + pub event_id: Option, } +impl CoverLetter { + pub fn get_branch_name(&self) -> Result { + Ok(format!( + "prs/{}({})", + self.branch_name, + &self + .event_id + .context("proposal root event_id must be know to get it's branch name")? + .to_hex() + .as_str()[..8], + )) + } +} pub fn event_is_cover_letter(event: &nostr::Event) -> bool { // TODO: look for Subject:[ PATCH 0/n ] but watch out for: // [PATCH v1 0/n ] or @@ -841,6 +855,7 @@ pub fn event_to_cover_letter(event: &nostr::Event) -> Result { .collect(); s }, + event_id: Some(event.id()), }) } -- cgit v1.2.3