fix(db): sqlite connector always reads/writes main worktree database

Same fix as the ticket CLI — uses git rev-parse --git-common-dir to
resolve DB path to the main worktree. Prevents WAL/journal pollution
when sqlite-query or sqlite-exec are called from feature branches.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-11 19:01:26 +01:00
co-authored by Claude Opus 4.6
parent 70a6f850c6
commit 0c7d44b265
+17 -2
View File
@@ -13,6 +13,7 @@ Usage:
import json
import os
import sqlite3
import subprocess
import sys
from pathlib import Path
@@ -25,12 +26,26 @@ CONFIG_PATH = SCRIPT_DIR / "config.json"
SCHEMA_PATH = SCRIPT_DIR.parent / "schema.sql"
def _main_worktree():
"""Find the main worktree root via git's common dir."""
try:
common = subprocess.check_output(
["git", "rev-parse", "--git-common-dir"],
stderr=subprocess.DEVNULL, text=True
).strip()
return Path(common).resolve().parent
except (subprocess.CalledProcessError, OSError):
return SCRIPT_DIR.parent.parent
def load_config():
"""Load config.json and resolve the SQLite database path."""
with open(CONFIG_PATH, "r") as f:
cfg = json.load(f)
# Resolve sqlite_db relative to the connectors directory
db_path = (SCRIPT_DIR / cfg["sqlite_db"]).resolve()
# Always resolve DB path in the main worktree to avoid
# WAL/journal pollution on feature branches causing merge conflicts.
main_root = _main_worktree()
db_path = (main_root / "db" / "commonwealth.db").resolve()
cfg["sqlite_db_resolved"] = str(db_path)
return cfg