Skip to content

feat: copy .gitignore-d files into new session worktrees - #26

Merged
takecchi merged 1 commit into
mainfrom
feat/copy-gitignored-into-worktree
Jul 19, 2026
Merged

feat: copy .gitignore-d files into new session worktrees#26
takecchi merged 1 commit into
mainfrom
feat/copy-gitignored-into-worktree

Conversation

@takecchi

Copy link
Copy Markdown
Owner

概要

セッションを新しく立ち上げるときの git worktree は、git 追跡対象のファイルしか引き継ぎません。そのため .gitignore された node_modules/.env などはコピーされず、各セッションで依存の再インストールや環境変数の再設定が必要でした。

この PR で、worktree 作成時にリポジトリルートの ignore された未追跡ファイルを複製するようにします(既定で有効)。

変更点

  • ignoredCopyEntries()(純関数・新規): git ls-files --others --ignored --exclude-standard --directory の出力をパースし、コピー対象エントリを返す。
    • --directory によりディレクトリ全体が ignore されている場合は末尾 / 付きの1エントリに畳まれる → node_modules/ を数万ファイル列挙せず1エントリで扱える。
    • .codiva/(worktree 群を再帰コピーしてしまう)と .git(内部状態破壊)は必ず除外。
  • WorktreeManager.copyIgnoredFiles(): fs.cp でエントリ単位のベストエフォート複製。1件の失敗で worktree 作成全体を止めない。
  • add(): copyIgnored が有効なら worktree 作成後にコピーを実行。
  • config: copyIgnored(既定 true)を追加。toConfig() で検証。"copyIgnored": false で無効化可能。
  • docs: README の設定セクション + ARCHITECTURE の WorktreeManager 記述を更新。

未ステージのファイル(作業途中の tracked 変更)は git worktree の仕様上そのまま引き継がれないため対象外です。この PR は「ignore されたファイルの複製」にフォーカスしています。

設計判断

  • 純粋ロジック(コピー対象の決定)と I/O(コピー実行)を分離(ignoredCopyEntries は純関数、テーブルドリブンでテスト)。
  • パフォーマンス配慮で --directory を使い、大量ファイルの列挙を回避。
  • 破壊を避けるため .codiva/ / .git を確実に除外。

テスト計画

  • ignoredCopyEntries の純関数テスト(.codiva/.git 除外、空入力)
  • 実 git リポジトリで node_modules/.env が worktree に複製されることを検証
  • .codiva/ が複製されないことを検証
  • copyIgnored: false で複製がスキップされることを検証
  • toConfig()copyIgnored 検証(boolean 受理・不正値ドロップ・全キー結合)
  • npm test(479 passed) / npm run typecheck / npm run lint(変更ファイルは警告0)

git worktree add only carries tracked files, so ignored artifacts like
node_modules/ and .env never appear in a fresh session worktree. This
forced each session to reinstall deps and re-create env files before it
could build or run.

WorktreeManager now copies the repo root's ignored, untracked entries
into every new worktree (enabled by default; opt out with the new
"copyIgnored": false config key).

- ignoredCopyEntries(): pure parser over `git ls-files --others --ignored
  --exclude-standard --directory` output. `--directory` collapses whole
  ignored dirs to one entry (node_modules/ stays a single entry instead
  of tens of thousands of files). Always drops .codiva/ and .git to avoid
  recursively copying worktrees or corrupting git internals.
- WorktreeManager.copyIgnoredFiles(): best-effort fs.cp per entry; a
  single failure never aborts worktree creation.
- config: add copyIgnored (default true) + validation in toConfig().
- docs: README config section + ARCHITECTURE WorktreeManager notes.
@takecchi
takecchi merged commit d1e189d into main Jul 19, 2026
1 check passed
@takecchi
takecchi deleted the feat/copy-gitignored-into-worktree branch July 19, 2026 10:40
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.

1 participant