upleb.uk

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

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/sub_commands/send.rs35
-rw-r--r--tests/list.rs2
-rw-r--r--tests/push.rs2
-rw-r--r--tests/send.rs10
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(
777 .context(format!("cannot find from_branch '{name}'"))?, 777 .context(format!("cannot find from_branch '{name}'"))?,
778 ), 778 ),
779 None => ( 779 None => (
780 "head".to_string(), 780 if let Ok(name) = git_repo.get_checked_out_branch_name() {
781 name
782 } else {
783 "head".to_string()
784 },
781 git_repo 785 git_repo
782 .get_head_commit() 786 .get_head_commit()
783 .context("failed to get head commit") 787 .context("failed to get head commit")
@@ -876,35 +880,6 @@ mod tests {
876 } 880 }
877 881
878 #[test] 882 #[test]
879 fn when_from_branch_is_none_return_as_head() -> Result<()> {
880 let test_repo = GitTestRepo::default();
881 let git_repo = Repo::from_path(&test_repo.dir)?;
882
883 test_repo.populate()?;
884 // create feature branch with 1 commit ahead
885 test_repo.create_branch("feature")?;
886 test_repo.checkout("feature")?;
887 std::fs::write(test_repo.dir.join("t3.md"), "some content")?;
888 let head_oid = test_repo.stage_and_commit("add t3.md")?;
889
890 // make feature branch 1 commit behind
891 test_repo.checkout("main")?;
892 std::fs::write(test_repo.dir.join("t4.md"), "some content")?;
893 let main_oid = test_repo.stage_and_commit("add t4.md")?;
894 // checkout feature
895 test_repo.checkout("feature")?;
896
897 let (from_branch, to_branch, ahead, behind) =
898 identify_ahead_behind(&git_repo, &None, &None)?;
899
900 assert_eq!(from_branch, "head");
901 assert_eq!(ahead, vec![oid_to_sha1(&head_oid)]);
902 assert_eq!(to_branch, "main");
903 assert_eq!(behind, vec![oid_to_sha1(&main_oid)]);
904 Ok(())
905 }
906
907 #[test]
908 fn when_from_branch_is_not_head_return_as_from_branch() -> Result<()> { 883 fn when_from_branch_is_not_head_return_as_from_branch() -> Result<()> {
909 let test_repo = GitTestRepo::default(); 884 let test_repo = GitTestRepo::default();
910 let git_repo = Repo::from_path(&test_repo.dir)?; 885 let git_repo = Repo::from_path(&test_repo.dir)?;
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 {
1710 c.succeeds_with(0, true, None)?; 1710 c.succeeds_with(0, true, None)?;
1711 p.expect("finding commits...\r\n")?; 1711 p.expect("finding commits...\r\n")?;
1712 p.expect("updated proposal available (2 ahead 0 behind 'main'). existing version is 2 ahead 1 behind 'main'\r\n")?; 1712 p.expect("updated proposal available (2 ahead 0 behind 'main'). existing version is 2 ahead 1 behind 'main'\r\n")?;
1713 // its got here but tmpgit-32.. indicates that creatubg the eature
1714 // branch in line 1291 didnt work so the choices will be different
1715 let mut c = p.expect_choice( 1713 let mut c = p.expect_choice(
1716 "", 1714 "",
1717 vec![ 1715 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 {
591 p.expect("preparing to force push proposal revision...\r\n")?; 591 p.expect("preparing to force push proposal revision...\r\n")?;
592 592
593 // standard output from `ngit send` 593 // standard output from `ngit send`
594 p.expect("creating patch for 2 commits from 'head' that can be merged into 'main'\r\n")?; 594 p.expect(format!("creating patch for 2 commits from '{FEATURE_BRANCH_NAME_1}' that can be merged into 'main'\r\n"))?;
595 p.expect("searching for profile and relay updates...\r\n")?; 595 p.expect("searching for profile and relay updates...\r\n")?;
596 p.expect("\r")?; 596 p.expect("\r")?;
597 p.expect("logged in as fred\r\n")?; 597 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<()> {
39 test_repo.checkout("feature")?; 39 test_repo.checkout("feature")?;
40 40
41 let mut p = CliTester::new_from_dir(&test_repo.dir, ["send"]); 41 let mut p = CliTester::new_from_dir(&test_repo.dir, ["send"]);
42 p.expect("Error: 'head' is 0 commits ahead of 'main' so no patches were created")?; 42 p.expect("Error: 'feature' is 0 commits ahead of 'main' so no patches were created")?;
43 Ok(()) 43 Ok(())
44} 44}
45 45
@@ -73,7 +73,7 @@ mod when_commits_behind_ask_to_proceed {
73 ahead: u8, 73 ahead: u8,
74 ) -> Result<CliTesterConfirmPrompt> { 74 ) -> Result<CliTesterConfirmPrompt> {
75 p.expect_confirm( 75 p.expect_confirm(
76 format!("'head' is {behind} commits behind 'main' and {ahead} ahead. Consider rebasing before sending patches. Proceed anyway?").as_str(), 76 format!("'feature' is {behind} commits behind 'main' and {ahead} ahead. Consider rebasing before sending patches. Proceed anyway?").as_str(),
77 Some(false), 77 Some(false),
78 ) 78 )
79 } 79 }
@@ -108,7 +108,7 @@ mod when_commits_behind_ask_to_proceed {
108 let mut p = CliTester::new_from_dir(&test_repo.dir, ["send"]); 108 let mut p = CliTester::new_from_dir(&test_repo.dir, ["send"]);
109 expect_confirm_prompt(&mut p, BEHIND_LEN, AHEAD_LEN)?.succeeds_with(Some(true))?; 109 expect_confirm_prompt(&mut p, BEHIND_LEN, AHEAD_LEN)?.succeeds_with(Some(true))?;
110 p.expect( 110 p.expect(
111 format!("creating patch for {AHEAD_LEN} commits from 'head' that are {BEHIND_LEN} behind 'main'",) 111 format!("creating patch for {AHEAD_LEN} commits from 'feature' that are {BEHIND_LEN} behind 'main'",)
112 .as_str(), 112 .as_str(),
113 )?; 113 )?;
114 p.exit()?; 114 p.exit()?;
@@ -131,7 +131,7 @@ fn cli_message_creating_patches() -> Result<()> {
131 131
132 let mut p = CliTester::new_from_dir(&test_repo.dir, ["send"]); 132 let mut p = CliTester::new_from_dir(&test_repo.dir, ["send"]);
133 133
134 p.expect("creating patch for 2 commits from 'head' that can be merged into 'main'")?; 134 p.expect("creating patch for 2 commits from 'feature' that can be merged into 'main'")?;
135 p.exit()?; 135 p.exit()?;
136 Ok(()) 136 Ok(())
137} 137}
@@ -184,7 +184,7 @@ fn cli_tester_create_proposal(git_repo: &GitTestRepo, include_cover_letter: bool
184} 184}
185 185
186fn expect_msgs_first(p: &mut CliTester, include_cover_letter: bool) -> Result<()> { 186fn expect_msgs_first(p: &mut CliTester, include_cover_letter: bool) -> Result<()> {
187 p.expect("creating patch for 2 commits from 'head' that can be merged into 'main'\r\n")?; 187 p.expect("creating patch for 2 commits from 'feature' that can be merged into 'main'\r\n")?;
188 p.expect("searching for profile and relay updates...\r\n")?; 188 p.expect("searching for profile and relay updates...\r\n")?;
189 p.expect("\r")?; 189 p.expect("\r")?;
190 p.expect("logged in as fred\r\n")?; 190 p.expect("logged in as fred\r\n")?;