upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/git.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/git.rs')
-rw-r--r--src/git.rs26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/git.rs b/src/git.rs
index bb2b8e7..6de9e90 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -147,7 +147,7 @@ impl RepoActions for Repo {
147 { 147 {
148 Ok(main_tuple) 148 Ok(main_tuple)
149 } else { 149 } else {
150 self.get_main_or_master_branch() 150 self.get_local_main_or_master_branch()
151 .context("the default branches (main or master) do not exist") 151 .context("the default branches (main or master) do not exist")
152 } 152 }
153 } 153 }
@@ -1124,6 +1124,30 @@ mod tests {
1124 mod get_main_or_master_branch { 1124 mod get_main_or_master_branch {
1125 1125
1126 use super::*; 1126 use super::*;
1127
1128 #[test]
1129 fn return_origin_main_if_exists() -> Result<()> {
1130 let test_origin_repo = GitTestRepo::new("main")?;
1131 let main_origin_oid = test_origin_repo.populate()?;
1132
1133 let test_repo = GitTestRepo::new("main")?;
1134 test_repo.populate()?;
1135 test_repo.add_remote("origin", test_origin_repo.dir.to_str().unwrap())?;
1136 test_repo
1137 .git_repo
1138 .find_remote("origin")?
1139 .fetch(&["main"], None, None)?;
1140
1141 std::fs::write(test_repo.dir.join("t3.md"), "some content")?;
1142 test_repo.stage_and_commit("add t3.md")?;
1143
1144 let git_repo = Repo::from_path(&test_repo.dir)?;
1145 let (name, commit_hash) = git_repo.get_main_or_master_branch()?;
1146 assert_eq!(name, "origin/main");
1147 assert_eq!(commit_hash, oid_to_sha1(&main_origin_oid));
1148 Ok(())
1149 }
1150
1127 mod returns_main { 1151 mod returns_main {
1128 use super::*; 1152 use super::*;
1129 #[test] 1153 #[test]