Skip to content

Commit 3293543

Browse files
committed
fix(worktree): exclude .klondike/ from diff when applying changes
When the agent runs klondike commands (feature start, verify, session end) inside a worktree, it modifies .klondike/features.json. These state changes conflict when trying to patch back to the main project. Now get_worktree_diff() excludes .klondike/ by default, so only code changes are applied. The klondike state in the main project remains authoritative.
1 parent da0b564 commit 3293543

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/klondike_spec_cli/worktree.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,19 +455,33 @@ def list_worktrees(project_dir: Path) -> list[WorktreeInfo]:
455455
return worktrees
456456

457457

458-
def get_worktree_diff(worktree_path: Path, parent_branch: str) -> str:
458+
def get_worktree_diff(
459+
worktree_path: Path,
460+
parent_branch: str,
461+
exclude_patterns: list[str] | None = None,
462+
) -> str:
459463
"""Get the diff of changes in a worktree compared to parent branch.
460464
461465
Args:
462466
worktree_path: Path to the worktree
463467
parent_branch: The parent branch to diff against
468+
exclude_patterns: List of path patterns to exclude (e.g., [".klondike/"])
464469
465470
Returns:
466471
Diff content as string
467472
"""
473+
# Default exclusions - klondike state files should not be patched
474+
if exclude_patterns is None:
475+
exclude_patterns = [".klondike/"]
476+
468477
try:
478+
cmd = ["git", "diff", parent_branch]
479+
# Add exclusion patterns
480+
for pattern in exclude_patterns:
481+
cmd.extend(["--", f":!{pattern}"])
482+
469483
result = subprocess.run(
470-
["git", "diff", parent_branch],
484+
cmd,
471485
capture_output=True,
472486
text=True,
473487
cwd=worktree_path,

0 commit comments

Comments
 (0)