Fail properly when default branch cannot be detected

This commit is contained in:
2022-05-26 16:18:56 +02:00
parent 1db3eadd4c
commit 50a0f4d766

View File

@@ -1271,14 +1271,14 @@ impl Repo {
}; };
let default_branch_name = match &config { let default_branch_name = match &config {
None => guess_default_branch()?, None => guess_default_branch().ok(),
Some(config) => match &config.persistent_branches { Some(config) => match &config.persistent_branches {
None => guess_default_branch()?, None => guess_default_branch().ok(),
Some(persistent_branches) => { Some(persistent_branches) => {
if persistent_branches.is_empty() { if persistent_branches.is_empty() {
guess_default_branch()? guess_default_branch().ok()
} else { } else {
persistent_branches[0].clone() Some(persistent_branches[0].clone())
} }
} }
}, },
@@ -1290,9 +1290,11 @@ impl Repo {
if dirname == WORKTREE_CONFIG_FILE_NAME { if dirname == WORKTREE_CONFIG_FILE_NAME {
continue; continue;
} }
if let Some(default_branch_name) = default_branch_name {
if dirname == default_branch_name { if dirname == default_branch_name {
continue; continue;
} }
}
if !&worktrees.iter().any(|worktree| worktree.name() == dirname) { if !&worktrees.iter().any(|worktree| worktree.name() == dirname) {
unmanaged_worktrees.push(dirname); unmanaged_worktrees.push(dirname);
} }