From b931b37e26486e4e6d15f302e87141dcf2f596ba Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Fri, 23 Feb 2024 08:30:15 +0000 Subject: refactor: remove confusing options, improve help from_branch and to_branch have been replaced by specifying revision ranges --- src/sub_commands/send.rs | 35 +++++------------------------------ tests/list.rs | 2 -- tests/push.rs | 2 +- tests/send.rs | 10 +++++----- 4 files changed, 11 insertions(+), 38 deletions(-) diff --git a/src/sub_commands/send.rs b/src/sub_commands/send.rs index ebe23b1..51169dc 100644 --- a/src/sub_commands/send.rs +++ b/src/sub_commands/send.rs @@ -777,7 +777,11 @@ fn identify_ahead_behind( .context(format!("cannot find from_branch '{name}'"))?, ), None => ( - "head".to_string(), + if let Ok(name) = git_repo.get_checked_out_branch_name() { + name + } else { + "head".to_string() + }, git_repo .get_head_commit() .context("failed to get head commit") @@ -875,35 +879,6 @@ mod tests { Ok(()) } - #[test] - fn when_from_branch_is_none_return_as_head() -> Result<()> { - let test_repo = GitTestRepo::default(); - let git_repo = Repo::from_path(&test_repo.dir)?; - - test_repo.populate()?; - // create feature branch with 1 commit ahead - test_repo.create_branch("feature")?; - test_repo.checkout("feature")?; - std::fs::write(test_repo.dir.join("t3.md"), "some content")?; - let head_oid = test_repo.stage_and_commit("add t3.md")?; - - // make feature branch 1 commit behind - test_repo.checkout("main")?; - std::fs::write(test_repo.dir.join("t4.md"), "some content")?; - let main_oid = test_repo.stage_and_commit("add t4.md")?; - // checkout feature - test_repo.checkout("feature")?; - - let (from_branch, to_branch, ahead, behind) = - identify_ahead_behind(&git_repo, &None, &None)?; - - assert_eq!(from_branch, "head"); - assert_eq!(ahead, vec![oid_to_sha1(&head_oid)]); - assert_eq!(to_branch, "main"); - assert_eq!(behind, vec![oid_to_sha1(&main_oid)]); - Ok(()) - } - #[test] fn when_from_branch_is_not_head_return_as_from_branch() -> Result<()> { let test_repo = GitTestRepo::default(); diff --git a/tests/list.rs b/tests/list.rs index ff54586..b6bcd08 100644 --- a/tests/list.rs +++ b/tests/list.rs @@ -1710,8 +1710,6 @@ mod when_main_branch_is_uptodate { c.succeeds_with(0, true, None)?; p.expect("finding commits...\r\n")?; p.expect("updated proposal available (2 ahead 0 behind 'main'). existing version is 2 ahead 1 behind 'main'\r\n")?; - // its got here but tmpgit-32.. indicates that creatubg the eature - // branch in line 1291 didnt work so the choices will be different let mut c = p.expect_choice( "", vec![ diff --git a/tests/push.rs b/tests/push.rs index 81daf0e..0705174 100644 --- a/tests/push.rs +++ b/tests/push.rs @@ -591,7 +591,7 @@ mod when_branch_is_checked_out { p.expect("preparing to force push proposal revision...\r\n")?; // standard output from `ngit send` - p.expect("creating patch for 2 commits from 'head' that can be merged into 'main'\r\n")?; + p.expect(format!("creating patch for 2 commits from '{FEATURE_BRANCH_NAME_1}' that can be merged into 'main'\r\n"))?; p.expect("searching for profile and relay updates...\r\n")?; p.expect("\r")?; p.expect("logged in as fred\r\n")?; diff --git a/tests/send.rs b/tests/send.rs index b5c803d..58c21f9 100644 --- a/tests/send.rs +++ b/tests/send.rs @@ -39,7 +39,7 @@ fn when_no_commits_ahead_of_main_return_error() -> Result<()> { test_repo.checkout("feature")?; let mut p = CliTester::new_from_dir(&test_repo.dir, ["send"]); - p.expect("Error: 'head' is 0 commits ahead of 'main' so no patches were created")?; + p.expect("Error: 'feature' is 0 commits ahead of 'main' so no patches were created")?; Ok(()) } @@ -73,7 +73,7 @@ mod when_commits_behind_ask_to_proceed { ahead: u8, ) -> Result { p.expect_confirm( - format!("'head' is {behind} commits behind 'main' and {ahead} ahead. Consider rebasing before sending patches. Proceed anyway?").as_str(), + format!("'feature' is {behind} commits behind 'main' and {ahead} ahead. Consider rebasing before sending patches. Proceed anyway?").as_str(), Some(false), ) } @@ -108,7 +108,7 @@ mod when_commits_behind_ask_to_proceed { let mut p = CliTester::new_from_dir(&test_repo.dir, ["send"]); expect_confirm_prompt(&mut p, BEHIND_LEN, AHEAD_LEN)?.succeeds_with(Some(true))?; p.expect( - format!("creating patch for {AHEAD_LEN} commits from 'head' that are {BEHIND_LEN} behind 'main'",) + format!("creating patch for {AHEAD_LEN} commits from 'feature' that are {BEHIND_LEN} behind 'main'",) .as_str(), )?; p.exit()?; @@ -131,7 +131,7 @@ fn cli_message_creating_patches() -> Result<()> { let mut p = CliTester::new_from_dir(&test_repo.dir, ["send"]); - p.expect("creating patch for 2 commits from 'head' that can be merged into 'main'")?; + p.expect("creating patch for 2 commits from 'feature' that can be merged into 'main'")?; p.exit()?; Ok(()) } @@ -184,7 +184,7 @@ fn cli_tester_create_proposal(git_repo: &GitTestRepo, include_cover_letter: bool } fn expect_msgs_first(p: &mut CliTester, include_cover_letter: bool) -> Result<()> { - p.expect("creating patch for 2 commits from 'head' that can be merged into 'main'\r\n")?; + p.expect("creating patch for 2 commits from 'feature' that can be merged into 'main'\r\n")?; p.expect("searching for profile and relay updates...\r\n")?; p.expect("\r")?; p.expect("logged in as fred\r\n")?; -- cgit v1.2.3