huskies: merge 1176 bug base_branch fallback hardcodes master instead of auto-detecting

This commit is contained in:
Huskies Agent
2026-07-16 16:22:46 +00:00
parent a4e2d4bc25
commit efd0097f76
11 changed files with 301 additions and 50 deletions
+2 -5
View File
@@ -5,7 +5,7 @@ use std::path::Path;
use std::process::Command;
use super::git::{
branch_name, configure_sparse_checkout, create_worktree_sync, detect_base_branch,
branch_name, configure_sparse_checkout, create_worktree_sync, resolve_base_branch,
};
use super::{WorktreeInfo, worktree_path, write_mcp_json};
@@ -42,10 +42,7 @@ pub async fn create_worktree(
) -> Result<WorktreeInfo, String> {
let wt_path = worktree_path(project_root, story_id);
let branch = branch_name(story_id);
let base_branch = config
.base_branch
.clone()
.unwrap_or_else(|| detect_base_branch(project_root));
let base_branch = resolve_base_branch(project_root, config.base_branch.as_deref());
let root = project_root.to_path_buf();
// Already exists — reuse without re-running destructive setup commands.
+13
View File
@@ -24,6 +24,19 @@ pub(crate) fn detect_base_branch(project_root: &Path) -> String {
.unwrap_or_else(|| "master".to_string())
}
/// Resolve the base branch to use for `project_root`.
///
/// Returns `configured` (typically `ProjectConfig.base_branch`) when set;
/// otherwise auto-detects the repository's default branch via
/// [`detect_base_branch`]. This is the single shared resolver for base-branch
/// fallback — production call sites must use it rather than hardcoding
/// `"master"` directly.
pub(crate) fn resolve_base_branch(project_root: &Path, configured: Option<&str>) -> String {
configured
.map(str::to_string)
.unwrap_or_else(|| detect_base_branch(project_root))
}
/// Placeholder for worktree isolation of `.huskies/work/`.
///
/// Previous approaches (sparse checkout, skip-worktree) all leaked state
+1 -1
View File
@@ -10,8 +10,8 @@ mod sweep;
pub use cleanup::{format_report, run_cleanup};
pub use create::create_worktree;
pub use create::install_pre_commit_hook;
pub(crate) use git::detect_base_branch;
pub use git::migrate_slug_paths;
pub(crate) use git::resolve_base_branch;
pub use remove::remove_worktree_by_story_id;
#[derive(Debug, Clone)]
+2 -5
View File
@@ -3,7 +3,7 @@ use crate::config::ProjectConfig;
use std::path::Path;
use super::create::run_teardown_commands;
use super::git::{branch_name, detect_base_branch, remove_worktree_sync};
use super::git::{branch_name, remove_worktree_sync, resolve_base_branch};
use super::{WorktreeInfo, worktree_path};
/// Remove a git worktree and its branch.
@@ -34,10 +34,7 @@ pub async fn remove_worktree_by_story_id(
return Err(format!("Worktree not found for story: {story_id}"));
}
let branch = branch_name(story_id);
let base_branch = config
.base_branch
.clone()
.unwrap_or_else(|| detect_base_branch(project_root));
let base_branch = resolve_base_branch(project_root, config.base_branch.as_deref());
let info = WorktreeInfo {
path,
branch,