Fix sparse checkout leaking from worktrees to main checkout
Use extensions.worktreeConfig + --worktree flag so core.sparseCheckout is set per-worktree only, preventing the main checkout from losing its .story_kit/work/ directory. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -161,9 +161,18 @@ fn create_worktree_sync(
|
|||||||
/// from being committed on feature branches, which avoids rename/delete merge
|
/// from being committed on feature branches, which avoids rename/delete merge
|
||||||
/// conflicts when merging back to master.
|
/// conflicts when merging back to master.
|
||||||
fn configure_sparse_checkout(wt_path: &Path) -> Result<(), String> {
|
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")
|
let output = Command::new("git")
|
||||||
.args(["config", "core.sparseCheckout", "true"])
|
.args(["config", "--worktree", "core.sparseCheckout", "true"])
|
||||||
.current_dir(wt_path)
|
.current_dir(wt_path)
|
||||||
.output()
|
.output()
|
||||||
.map_err(|e| format!("sparse-checkout config: {e}"))?;
|
.map_err(|e| format!("sparse-checkout config: {e}"))?;
|
||||||
@@ -475,5 +484,12 @@ mod tests {
|
|||||||
|
|
||||||
// Other files should still exist
|
// Other files should still exist
|
||||||
assert!(wt_path.join(".git").exists());
|
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"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user