Refactor default_branch() for readability
This commit is contained in:
14
src/repo.rs
14
src/repo.rs
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user