Skip to content

Fall back to launch dir when resolving project root outside git#13

Merged
bguidolim merged 1 commit into
mainfrom
bruno/nogit-project-root-fallback
Jul 9, 2026
Merged

Fall back to launch dir when resolving project root outside git#13
bguidolim merged 1 commit into
mainfrom
bruno/nogit-project-root-fallback

Conversation

@bguidolim

Copy link
Copy Markdown
Collaborator

Why

The sync-memories hook resolved the project root exclusively through git rev-parse --show-toplevel and bailed silently (|| exit 0) when it failed. In a non-git folder this meant memories were never indexed, with no visible error.

PR #11 fixed this same bug but was reverted in #12 for bundling too much unrelated hardening (diagnostic logging, doc-count verification, embedding env var, scrape/refresh rework) into one change. This PR extracts just the non-git fallback, nothing else.

Change

hooks/sync-memories.sh: when git rev-parse yields nothing, fall back to CLAUDE_PROJECT_DIR, then $PWD. Git-repo resolution (anchoring to the toplevel) is unchanged.

Test plan

  • bash -n syntax check
  • From a non-git scratch dir with .claude/memories/*.md, ran the hook directly — it resolved project_root to the scratch dir, indexed it into docs-mcp-server (confirmed via list), and wrote .memories-last-indexed
  • Non-git dir with no .claude/memories — hook exits 0, no side effects
  • From a subdirectory of this git repo, hook still resolves to the repo toplevel (unchanged)

- git rev-parse failure in non-git folders no longer aborts the hook
- Falls back to CLAUDE_PROJECT_DIR, then $PWD, so memories index correctly
- Git-repo resolution (toplevel anchor) is unchanged
@bguidolim
bguidolim merged commit b0662f5 into main Jul 9, 2026
@bguidolim
bguidolim deleted the bruno/nogit-project-root-fallback branch July 9, 2026 16:57
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