diff --git a/server/src/worktree.rs b/server/src/worktree.rs index b622d2f..3dc024e 100644 --- a/server/src/worktree.rs +++ b/server/src/worktree.rs @@ -161,9 +161,18 @@ fn create_worktree_sync( /// from being committed on feature branches, which avoids rename/delete merge /// conflicts when merging back to master. fn configure_sparse_checkout(wt_path: &Path) -> Result<(), String> { - // Enable sparse checkout via git config (non-cone mode for pattern support) + // Enable worktree-specific config so sparse checkout settings don't leak + // to the main checkout or other worktrees. + let _ = Command::new("git") + .args(["config", "extensions.worktreeConfig", "true"]) + .current_dir(wt_path) + .output(); + + // Enable sparse checkout for THIS worktree only (--worktree flag). + // Without --worktree, this writes to the shared .git/config and + // enables sparse checkout on the main checkout too. let output = Command::new("git") - .args(["config", "core.sparseCheckout", "true"]) + .args(["config", "--worktree", "core.sparseCheckout", "true"]) .current_dir(wt_path) .output() .map_err(|e| format!("sparse-checkout config: {e}"))?; @@ -475,5 +484,12 @@ mod tests { // Other files should still exist assert!(wt_path.join(".git").exists()); + + // Main checkout must NOT be affected by the worktree's sparse checkout. + // The .story_kit/work/ directory must still exist in the project root. + assert!( + work_dir.exists(), + ".story_kit/work/ must still exist in the main checkout" + ); } }