feat: add codegraph auto-init-repos command#321
Open
CagesThrottleUs wants to merge 17 commits into
Open
Conversation
stripMarkerBlock, isEffectivelyEmpty, and chmodExecutable were duplicated in git-hooks.ts. Extracting them here lets global-hooks.ts reuse the same logic without copy-pasting, and pins their contracts with 11 explicit unit tests.
Installs a post-checkout snippet into the git template directory so every new git clone automatically runs codegraph init + index. Uses the same marker-block pattern as the per-repo sync hooks, with full idempotency and surgical remove that preserves user hook content.
Extracts the auto-init-repos command handler into its own module so tests can import it directly and mock global-hooks without spawning a subprocess. Clack is injected via parameter to avoid ESM dynamic import issues in the test environment.
…guard Three fixes: normalize trailing whitespace before the unchanged equality check so re-installs are not spuriously written; gate mkdirSync in resolveTemplateDir to only run when writeConfig is true, preventing ~/.git-templates/hooks/ from being silently created by remove/status calls; add a \$3=1 guard to the hook script so it skips file-level git checkout calls and only fires on actual branch switches.
Documents the new auto-init-repos command in the Initialize Projects section and adds it to the CLI reference table so users can discover the zero-config cloning workflow.
Resolves conflict in codegraph.ts: upstream added codegraph uninstall, this branch added auto-init-repos — both commands kept in order.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this adds
A new
codegraph auto-init-reposcommand that installs a global git template hook so every subsequentgit cloneorgit initautomatically runscodegraph initandcodegraph index— no manual step required per repo.How it works
Git copies the contents of
~/.git-templates/into every new repo's.git/at clone/init time. The command writes apost-checkouthook into that directory. On first checkout after a clone, the hook:.codegraph/existscodegraph init .+codegraph index, and appends.codegraph/to.gitignore(idempotent viagrep -qxF)codegraph syncin the background (non-blocking)The hook is guarded by
command -v codegraphso it no-ops silently on machines where CodeGraph is not installed. It also checks$3 = 1to skip file-levelgit checkout -- filecalls and only fire on actual branch switches/clones.Platform scope: macOS, Linux, Git for Windows (MINGW). Native Windows cmd/PowerShell is out of scope.
Code structure
Tests
53 new tests across 3 test files, all passing. Full suite: 770 tests, 0 failures.
__tests__/hook-utils.test.ts__tests__/global-hooks.test.ts__tests__/auto-init-repos-cli.test.ts__tests__/git-hooks.test.tsTests use
GIT_CONFIG_GLOBALenv var isolation so they never touch the real~/.gitconfig.Design spec
Full requirements, test traceability matrix, and design decisions are in:
docs/superpowers/specs/2026-05-22-auto-init-repos-design.mdEvery line of code maps back to a named requirement (
REQ-HU-xx,REQ-GL-xx,REQ-CLI-xx). Every requirement has at least one test ID.Install / remove behavior
~/.git-templates/hooks/post-checkout, setsgit config --global init.templateDirif not already set--removewith shared hook--removewhen only ours--removenevergit config init.templateDir