Keep default-branch discovery local

This commit is contained in:
Chris Bookholt
2026-06-17 10:47:54 -07:00
parent 0065c3a17d
commit eb45c01ea9
3 changed files with 111 additions and 58 deletions

View File

@@ -474,8 +474,7 @@ async fn get_git_remotes(cwd: &Path) -> Option<Vec<String>> {
///
/// Preference order:
/// 1) The symbolic ref at `refs/remotes/<remote>/HEAD` for the first remote (origin prioritized)
/// 2) `git remote show <remote>` parsed for "HEAD branch: <name>"
/// 3) Local fallback to existing `main` or `master` if present
/// 2) Local fallback to existing `main` or `master` if present
async fn get_default_branch(cwd: &Path) -> Option<String> {
// Prefer the first remote (with origin prioritized)
let remotes = get_git_remotes(cwd).await.unwrap_or_default();
@@ -498,23 +497,6 @@ async fn get_default_branch(cwd: &Path) -> Option<String> {
return Some(name.to_string());
}
}
// Fall back to parsing `git remote show <remote>` output
if let Some(show_output) =
run_git_command_with_timeout(&["remote", "show", &remote], cwd).await
&& show_output.status.success()
&& let Ok(text) = String::from_utf8(show_output.stdout)
{
for line in text.lines() {
let line = line.trim();
if let Some(rest) = line.strip_prefix("HEAD branch:") {
let name = rest.trim();
if !name.is_empty() {
return Some(name.to_string());
}
}
}
}
}
// No remote-derived default; try common local defaults if they exist