Refactor default_branch() for readability

This commit is contained in:
2022-06-08 17:04:20 +02:00
parent 60eb059f60
commit d26b6e799c

View File

@@ -1035,13 +1035,15 @@ impl RepoHandle {
} }
pub fn default_branch(&self) -> Result<Branch, String> { pub fn default_branch(&self) -> Result<Branch, String> {
match self.0.find_branch("main", git2::BranchType::Local) { let branch_names = vec!["main", "master"];
Ok(branch) => Ok(Branch(branch)),
Err(_) => match self.0.find_branch("master", git2::BranchType::Local) { for branch_name in &branch_names {
Ok(branch) => Ok(Branch(branch)), if let Ok(branch) = self.0.find_branch(branch_name, git2::BranchType::Local) {
Err(_) => Err(String::from("Could not determine default branch")), return Ok(Branch(branch))
}, }
} }
Err(String::from("Could not determine default branch"))
} }
// Looks like there is no distinguishing between the error cases // Looks like there is no distinguishing between the error cases