Skip to content

feat(cli): auto-seed git worktrees from their base checkout#747

Merged
RaghavChamadiya merged 1 commit into
mainfrom
feat/worktree-auto-seed
Jul 10, 2026
Merged

feat(cli): auto-seed git worktrees from their base checkout#747
RaghavChamadiya merged 1 commit into
mainfrom
feat/worktree-auto-seed

Conversation

@RaghavChamadiya

Copy link
Copy Markdown
Member

What

Makes git worktrees seamless: repowise init and repowise update inside a linked worktree now detect the base checkout automatically (via git rev-parse --git-common-dir), seed the worktree's index from it, and catch up incrementally. No flags, no paths. Follow-up to #655, which introduced the manual --seed-from flag.

cd my-feature-worktree
repowise update
[worktree] Unindexed linked worktree of /path/to/base; seeding its index.
  • --seed-from <path> stays as an explicit override for unusual layouts
  • new --no-seed forces a cold init inside a worktree
  • update auto-seeding means post-commit hooks and coding agents running in a fresh worktree get the fast path with zero setup

Bug fixes along the way

Seeded indexes no longer split in two. upsert_repository matches by local_path, so a seeded wiki.db still pointed at the base checkout; the first update in the worktree minted a second repository row named after the worktree dir and regenerated everything under it, while the seeded pages stayed orphaned under the old row (breaking prior-page reuse and repo-scoped queries). Seeding now adopts the copied row: name and local_path are re-pointed at the worktree and the repo-level pages are retargeted.

[workspace] notices render again. [dim][workspace][/dim] was being parsed as console markup and printed without its prefix. Both the workspace notice and the new [worktree] notice are escaped.

The #655 test suite is green again. The seed tests were failing on main's CI (integration tests only run on push to main, so the PR run never exercised them) and failed differently on Windows:

  • raw git commit calls without identity env (exit 128 on CI runners); now routed through the identity-injecting _git helper
  • git checkout main assumed the default branch name; now captured via rev-parse
  • with sqlite3.connect(...) never closes the handle, which broke worktree cleanup on Windows; replaced with closed-connection helpers
  • the git_work_repo fixture pins REPOWISE_DB_URL to the base repo's db, silently routing the worktree's delegated update into the wrong database; the seed tests now drop the env var and use repo-local DBs
  • substring assertions broke when Rich line-wrapped long Windows temp paths; whitespace is collapsed before matching
  • cleanup order (rmtree before git worktree remove) left git bookkeeping pointing at a missing dir

The index-only survival assertion moved from wiki_pages (empty in index-only runs) to graph_nodes, and the "new file gets a page" assertion is dropped: update-time coverage budgeting prevents it on every platform, tracked as #746.

Docs

New docs/WORKTREES.md (behavior, skip conditions, overrides, troubleshooting); WORKSPACES FAQ, CLI_REFERENCE, README, and QUICKSTART updated; changelog entries added under Unreleased (and the #655 entry moved out of the 0.25.0 section it had landed in).

Testing

  • 5 new unit tests for worktree detection and seed preconditions
  • 4 new integration tests (init auto-seed, --no-seed, update auto-seed, unindexed-base fallback) plus the 5 repaired feat(cli): allow seeding worktree index from base branch #655 tests
  • full tests/integration/test_cli.py (28) and tests/unit/cli + tests/unit/workspace (1162) green on Windows; end-to-end verified manually with the mock provider (single repository row, seeded pages reused, state advanced to worktree HEAD)

repowise init and repowise update inside a linked worktree now detect the
base checkout via git rev-parse --git-common-dir and seed the worktree's
index from it automatically, then catch up incrementally. --seed-from
becomes an explicit override; --no-seed forces a cold init.

The seed logic moves from init_cmd into a shared cli/worktree.py used by
both commands, and gains a repository-identity adoption step: the copied
wiki.db row is re-pointed (name + local_path) at the worktree, since
upsert_repository matches by local_path and the first update otherwise
minted a second repository row and split the index in two.

Also fixes the workspace auto-detect notice, whose [workspace] prefix was
silently consumed as console markup, and repairs the #655 seed tests,
which were red on main CI (raw git commits without identity) and on
Windows (default-branch assumption, unclosed sqlite handles breaking
worktree cleanup, REPOWISE_DB_URL fixture routing both repos into one db,
line-wrapped substring assertions). The new-file page assertion is
dropped: update-time coverage budgeting prevents it repo-wide (#746).

Docs: new WORKTREES.md, WORKSPACES FAQ, CLI_REFERENCE, README,
QUICKSTART, changelogs.
@repowise-bot

repowise-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown

✅ Health: 7.7 (unchanged)

📋 At a glance
4 hotspots touched · 4 new findings introduced · 5 co-change pairs left out · 4 files with recent fix history · 2 dead-code findings.

Files & modules (2)
  • packages (3 files)
    • .../init_cmd/command.py
    • .../update_cmd/command.py
    • .../cli/helpers.py
  • tests (1 file)
    • tests/integration/test_cli.py

⚠️ Change risk: moderate (riskier than 64% of this repo's commits · raw 9.3/10)
This change's risk is driven by:

  • more lines added than baseline
  • more scattered than baseline

🩹 Review priority (files here with the most recent bug-fix history — defects cluster, so review these first)

🔎 More signals (3)

🔥 Hotspots touched (4)

  • .../init_cmd/command.py — 14 commits/90d, 1 dependents · primary owner: Raghav Chamadiya (82%)
  • .../update_cmd/command.py — 10 commits/90d, 3 dependents · primary owner: Raghav Chamadiya (90%)
  • .../cli/helpers.py — 23 commits/90d, 68 dependents · primary owner: Raghav Chamadiya (72%)
1 more
  • tests/integration/test_cli.py — 8 commits/90d, 1 dependents · primary owner: Paarth SIkka (36%)

🔗 Hidden coupling (3 files)

  • .../cli/helpers.py co-changes with these files (not in this PR):
    • .../cli/test_helpers.py (9× — 🟢 routine)
    • docs/CLI_REFERENCE.md (5× — 🟢 routine)
  • .../init_cmd/command.py co-changes with these files (not in this PR):
    • docs/CLI_REFERENCE.md (7× — 🟢 routine)
    • .../init_cmd/workspace.py (6× — 🟢 routine)
  • .../update_cmd/command.py co-changes with .../update_cmd/persistence.py (5× — 🟢 routine) — not in this PR.

💀 Dead code (2 findings)

  • 💀 .../cli/helpers.py ensure_db (confidence 1.00)
  • 💀 .../cli/helpers.py is_interactive_session (confidence 1.00)

📊 Full report · ⭐ Star Repowise · 📥 Install bot · Last updated 2026-07-10 10:32 UTC
Silence on a single PR with [skip repowise] in the title · Per-repo toggle on repowise.dev/settings?tab=bot

@swati510 swati510 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@RaghavChamadiya RaghavChamadiya merged commit 11cc24f into main Jul 10, 2026
7 checks passed
@RaghavChamadiya RaghavChamadiya deleted the feat/worktree-auto-seed branch July 10, 2026 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants