upleb.uk

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

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-07-24 15:01:49 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2024-07-24 15:25:43 +0100
commit9078d0d80d1fe98ec9e6cd116c3dd70b6e0dd55a (patch)
tree7211ad8005b8c00dd7afa14533519929c440b564
parentdc05e1ca72d4c7eec9e6aeb989c2aef35a33aab8 (diff)
feat(push): `--force` tries non-interactively
if branch is ahead of main or master
-rw-r--r--src/sub_commands/push.rs24
-rw-r--r--src/sub_commands/send.rs2
-rw-r--r--tests/push.rs14
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::{
16 get_most_recent_patch_with_ancestors, get_proposals_and_revisions_from_cache, 16 get_most_recent_patch_with_ancestors, get_proposals_and_revisions_from_cache,
17 tag_value, 17 tag_value,
18 }, 18 },
19 send::{event_is_revision_root, event_to_cover_letter, generate_patch_event, send_events}, 19 send::{
20 event_is_revision_root, event_to_cover_letter, generate_patch_event,
21 identify_ahead_behind, send_events,
22 },
20 }, 23 },
21 Cli, 24 Cli,
22}; 25};
@@ -26,9 +29,6 @@ pub struct SubCommandArgs {
26 #[arg(long, action)] 29 #[arg(long, action)]
27 /// send proposal revision from checked out proposal branch 30 /// send proposal revision from checked out proposal branch
28 force: bool, 31 force: bool,
29 #[arg(long, action)]
30 /// dont prompt for cover letter when force pushing
31 no_cover_letter: bool,
32} 32}
33 33
34#[allow(clippy::too_many_lines)] 34#[allow(clippy::too_many_lines)]
@@ -116,11 +116,23 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
116 sub_commands::send::launch( 116 sub_commands::send::launch(
117 cli_args, 117 cli_args,
118 &sub_commands::send::SubCommandArgs { 118 &sub_commands::send::SubCommandArgs {
119 since_or_range: String::new(), 119 // if not ahead of master prompt, otherwise assume proposal revision is all commits
120 // ahead
121 since_or_range: if let Ok((_, _, ahead, _)) =
122 identify_ahead_behind(&git_repo, &None, &None)
123 {
124 if ahead.is_empty() {
125 String::new()
126 } else {
127 format!("HEAD~{}", ahead.len())
128 }
129 } else {
130 String::new()
131 },
120 in_reply_to: vec![proposal_root_event.id.to_string()], 132 in_reply_to: vec![proposal_root_event.id.to_string()],
121 title: None, 133 title: None,
122 description: None, 134 description: None,
123 no_cover_letter: args.no_cover_letter, 135 no_cover_letter: true,
124 }, 136 },
125 true, 137 true,
126 ) 138 )
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(
1042/** 1042/**
1043 * returns `(from_branch,to_branch,ahead,behind)` 1043 * returns `(from_branch,to_branch,ahead,behind)`
1044 */ 1044 */
1045fn identify_ahead_behind( 1045pub fn identify_ahead_behind(
1046 git_repo: &Repo, 1046 git_repo: &Repo,
1047 from_branch: &Option<String>, 1047 from_branch: &Option<String>,
1048 to_branch: &Option<String>, 1048 to_branch: &Option<String>,
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 {
478 "--disable-cli-spinners", 478 "--disable-cli-spinners",
479 "push", 479 "push",
480 "--force", 480 "--force",
481 "--no-cover-letter",
482 ], 481 ],
483 ); 482 );
484 p.expect("fetching updates...\r\n")?; 483 p.expect("fetching updates...\r\n")?;
@@ -488,19 +487,6 @@ mod when_branch_is_checked_out {
488 p.expect("creating proposal revision for: ")?; 487 p.expect("creating proposal revision for: ")?;
489 // proposal id will be printed in this gap 488 // proposal id will be printed in this gap
490 p.expect_eventually("\r\n")?; 489 p.expect_eventually("\r\n")?;
491 let mut selector = p.expect_multi_select(
492 "select commits for proposal",
493 vec![
494 format!("(Joe Bloggs) add a4.md [{branch_name}] 355bdf1"),
495 "(Joe Bloggs) add a3.md dbd1115".to_string(),
496 "(Joe Bloggs) commit for rebasing on top of [main] 1aa2cfe"
497 .to_string(),
498 "(Joe Bloggs) add t2.md 431b84e".to_string(),
499 "(Joe Bloggs) add t1.md af474d8".to_string(),
500 "(Joe Bloggs) Initial commit 9ee507f".to_string(),
501 ],
502 )?;
503 selector.succeeds_with(vec![0, 1], false, vec![0, 1])?;
504 p.expect("creating proposal from 2 commits:\r\n")?; 490 p.expect("creating proposal from 2 commits:\r\n")?;
505 p.expect("355bdf1 add a4.md\r\n")?; 491 p.expect("355bdf1 add a4.md\r\n")?;
506 p.expect("dbd1115 add a3.md\r\n")?; 492 p.expect("dbd1115 add a3.md\r\n")?;