upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-02-23 08:30:15 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2024-02-23 10:11:56 +0000
commitb931b37e26486e4e6d15f302e87141dcf2f596ba (patch)
treecf8cf7519c6bebc979ceca318b5c49cafc4fc870 /src
parent84d8f03cf2471d3530f4657055f272474880b6b5 (diff)
refactor: remove confusing options, improve help
from_branch and to_branch have been replaced by specifying revision ranges
Diffstat (limited to 'src')
-rw-r--r--src/sub_commands/send.rs35
1 files changed, 5 insertions, 30 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)?;