From 9078d0d80d1fe98ec9e6cd116c3dd70b6e0dd55a Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Wed, 24 Jul 2024 15:01:49 +0100 Subject: feat(push): `--force` tries non-interactively if branch is ahead of main or master --- src/sub_commands/push.rs | 24 ++++++++++++++++++------ src/sub_commands/send.rs | 2 +- tests/push.rs | 14 -------------- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/sub_commands/push.rs b/src/sub_commands/push.rs index 9af8b40..acd91f0 100644 --- a/src/sub_commands/push.rs +++ b/src/sub_commands/push.rs @@ -16,7 +16,10 @@ use crate::{ get_most_recent_patch_with_ancestors, get_proposals_and_revisions_from_cache, tag_value, }, - send::{event_is_revision_root, event_to_cover_letter, generate_patch_event, send_events}, + send::{ + event_is_revision_root, event_to_cover_letter, generate_patch_event, + identify_ahead_behind, send_events, + }, }, Cli, }; @@ -26,9 +29,6 @@ pub struct SubCommandArgs { #[arg(long, action)] /// send proposal revision from checked out proposal branch force: bool, - #[arg(long, action)] - /// dont prompt for cover letter when force pushing - no_cover_letter: bool, } #[allow(clippy::too_many_lines)] @@ -116,11 +116,23 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { sub_commands::send::launch( cli_args, &sub_commands::send::SubCommandArgs { - since_or_range: String::new(), + // if not ahead of master prompt, otherwise assume proposal revision is all commits + // ahead + since_or_range: if let Ok((_, _, ahead, _)) = + identify_ahead_behind(&git_repo, &None, &None) + { + if ahead.is_empty() { + String::new() + } else { + format!("HEAD~{}", ahead.len()) + } + } else { + String::new() + }, in_reply_to: vec![proposal_root_event.id.to_string()], title: None, description: None, - no_cover_letter: args.no_cover_letter, + no_cover_letter: true, }, true, ) diff --git a/src/sub_commands/send.rs b/src/sub_commands/send.rs index 6b9dd58..9733cfe 100644 --- a/src/sub_commands/send.rs +++ b/src/sub_commands/send.rs @@ -1042,7 +1042,7 @@ pub async fn generate_patch_event( /** * returns `(from_branch,to_branch,ahead,behind)` */ -fn identify_ahead_behind( +pub fn identify_ahead_behind( git_repo: &Repo, from_branch: &Option, to_branch: &Option, diff --git a/tests/push.rs b/tests/push.rs index 8ef7a30..eb452cd 100644 --- a/tests/push.rs +++ b/tests/push.rs @@ -478,7 +478,6 @@ mod when_branch_is_checked_out { "--disable-cli-spinners", "push", "--force", - "--no-cover-letter", ], ); p.expect("fetching updates...\r\n")?; @@ -488,19 +487,6 @@ mod when_branch_is_checked_out { p.expect("creating proposal revision for: ")?; // proposal id will be printed in this gap p.expect_eventually("\r\n")?; - let mut selector = p.expect_multi_select( - "select commits for proposal", - vec![ - format!("(Joe Bloggs) add a4.md [{branch_name}] 355bdf1"), - "(Joe Bloggs) add a3.md dbd1115".to_string(), - "(Joe Bloggs) commit for rebasing on top of [main] 1aa2cfe" - .to_string(), - "(Joe Bloggs) add t2.md 431b84e".to_string(), - "(Joe Bloggs) add t1.md af474d8".to_string(), - "(Joe Bloggs) Initial commit 9ee507f".to_string(), - ], - )?; - selector.succeeds_with(vec![0, 1], false, vec![0, 1])?; p.expect("creating proposal from 2 commits:\r\n")?; p.expect("355bdf1 add a4.md\r\n")?; p.expect("dbd1115 add a3.md\r\n")?; -- cgit v1.2.3