{"record":{"id":"c06ef52273452f97","repo":"Hmbown/CodeWhale","slug":"worktree-branch-must-not-be-empty","errorCode":null,"errorMessage":"worktree branch must not be empty","messagePattern":"worktree branch must not be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/lane/src/worktree.rs","lineNumber":33,"sourceCode":"    pub repo_root: PathBuf,\n    /// Branch to create (from `base_ref`).\n    pub branch: String,\n    /// Directory for the new worktree (created by `git worktree add`).\n    pub path: PathBuf,\n    /// Base ref to branch from (default `HEAD`).\n    pub base_ref: Option<String>,\n}\n\n#[derive(Debug, Clone)]\npub struct ProvisionedWorktree {\n    pub path: PathBuf,\n    pub branch: String,\n}\n\n/// Create a git worktree + branch for a lane.\npub fn provision_worktree(spec: &WorktreeProvision) -> Result<ProvisionedWorktree> {\n    if spec.branch.trim().is_empty() {\n        bail!(\"worktree branch must not be empty\");\n    }\n    if !spec.repo_root.exists() {\n        bail!(\"repo root does not exist: {}\", spec.repo_root.display());\n    }\n    if let Some(parent) = spec.path.parent() {\n        fs::create_dir_all(parent)\n            .with_context(|| format!(\"create worktree parent {}\", parent.display()))?;\n    }\n    let base = spec.base_ref.as_deref().unwrap_or(\"HEAD\");\n    // Capture git output instead of inheriting the caller's terminal. Runtime\n    // callers include the raw-mode TUI launch screen, where even one inherited\n    // progress/error line corrupts the alternate-screen buffer.\n    let output = Command::new(\"git\")\n        .current_dir(&spec.repo_root)\n        .args([\n            \"worktree\",\n            \"add\",\n            \"-b\",","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/lane/src/worktree.rs#L15-L51","documentation":"Input validation in `provision_worktree` (crates/lane/src/worktree.rs): the `WorktreeProvision.branch` field is empty or whitespace-only. A worktree needs a branch name to `git worktree add -b`, so the library fails fast before touching the filesystem or git.","triggerScenarios":"Calling `provision_worktree` with `WorktreeProvision { branch: \"\" }`, a branch of only spaces, or a branch derived from an unset/empty lane name or config field.","commonSituations":"Lane name interpolated from an env var that is unset; a config file where `branch` is omitted and defaults to `String::default()`; programmatic provisioning where the branch was supposed to be derived from user input that arrived empty.","solutions":["Populate `branch` with a non-empty name before calling provision_worktree (e.g. derive it from the lane id).","Validate/trim the lane name or config field that feeds `branch` at load time.","Provide an explicit branch in the lane spec instead of relying on defaults."],"exampleFix":"// before\nWorktreeProvision { branch: String::new(), .. }\n// after\nWorktreeProvision { branch: format!(\"lane/{}\", lane_id), .. }","handlingStrategy":"validation","validationCode":"let branch = spec.branch.trim();\nanyhow::ensure!(!branch.is_empty(), \"branch required before provisioning worktree\");","typeGuard":"fn valid_branch(b: &str) -> bool { !b.trim().is_empty() }","tryCatchPattern":null,"preventionTips":["Derive branch from lane id with a non-empty fallback at construction time.","Validate config fields feeding WorktreeProvision at load time.","Never pass String::default() as a branch."],"tags":["worktree","validation","git"],"backgroundTag":"empty-required-field","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}