fix: resolve default branch explicitly when updating shallow-cloned custom modules#2332
Conversation
🤖 Augment PR SummarySummary: Fixes stale updates for shallow-cloned custom modules by resolving and fetching the repository’s default branch explicitly instead of relying on Changes:
Technical Notes: Versioned installs now fetch a specific ref and check out 🤖 Was this summary useful? React with 👍 or 👎 |
b4fd9fb to
613df10
Compare
📝 WalkthroughWalkthroughEnhances Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Parser
participant Git as Git Operations
participant FS as File System
participant Resolver as Module Resolver
User->>Parser: Provide input (URL or path ± `@ref`)
Parser->>Parser: Extract/validate ref from suffix or URL path
Parser->>Git: Determine clone version (pinned vs default)
alt Pinned (explicit version)
Git->>Git: Clone/fetch with --branch <ref>
Git->>FS: Checkout FETCH_HEAD
else Unpinned (default branch)
Git->>Git: Resolve origin/HEAD
Git->>Git: Fetch default branch
Git->>FS: Hard-reset to origin/<branch>
end
Git->>FS: Record resolved sha & version to .bmad-source.json
FS->>Resolver: Propagate cloneRef, cloneSha, rawInput
Resolver->>User: Return resolved module with metadata
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related issues
Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tools/installer/modules/custom-module-manager.js (1)
360-367: Optional: drop the now-redundant generic fetch.Both branches below (pinned at line 372, unpinned at line 394) issue their own explicit
git fetch --depth 1 origin <ref>. The genericgit fetch origin --depth 1at line 363 is no longer needed and just adds an extra network round-trip on every update.♻️ Suggested simplification
fetchSpinner.start(`Updating ${displayName}...`); try { - execSync('git fetch origin --depth 1', { - cwd: repoCacheDir, - stdio: ['ignore', 'pipe', 'pipe'], - env: { ...process.env, GIT_TERMINAL_PROMPT: '0' }, - }); if (effectiveVersion) {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tools/installer/modules/custom-module-manager.js` around lines 360 - 367, Remove the redundant generic fetch call that performs execSync('git fetch origin --depth 1', { cwd: repoCacheDir, ... }) inside the update flow: the branch-specific fetches later (the pinned and unpinned paths that call 'git fetch --depth 1 origin <ref>') already fetch the required refs, so delete the generic fetch block (including the createSpinner/fetchSpinner start immediately preceding it) to avoid an extra network round-trip; ensure any spinner created for that generic fetch is removed or reused so there are no orphaned spinner variables (look for createSpinner, fetchSpinner, and the execSync call using repoCacheDir).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tools/installer/modules/custom-module-manager.js`:
- Around line 360-367: Remove the redundant generic fetch call that performs
execSync('git fetch origin --depth 1', { cwd: repoCacheDir, ... }) inside the
update flow: the branch-specific fetches later (the pinned and unpinned paths
that call 'git fetch --depth 1 origin <ref>') already fetch the required refs,
so delete the generic fetch block (including the createSpinner/fetchSpinner
start immediately preceding it) to avoid an extra network round-trip; ensure any
spinner created for that generic fetch is removed or reused so there are no
orphaned spinner variables (look for createSpinner, fetchSpinner, and the
execSync call using repoCacheDir).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 5ee42720-52c6-41f7-b6d7-37a7fbf0c6ab
📒 Files selected for processing (1)
tools/installer/modules/custom-module-manager.js
9443c7f to
f9fd7ae
Compare
…ustom modules With shallow clones (--depth 1), `origin/HEAD` becomes stale after the initial clone. The update path used `git reset --hard origin/HEAD` which never picked up new commits pushed to the default branch. Resolve the default branch name via `git symbolic-ref refs/remotes/origin/HEAD`, then fetch and reset against `origin/<branch>` explicitly. Falls back to `main` if origin/HEAD is not set.
f9fd7ae to
4d39db5
Compare
Summary
--depth 1clones,origin/HEADbecomes stale after the initial clone. The update path usedgit reset --hard origin/HEADwhich never picked up new commits pushed to the default branch.git symbolic-ref refs/remotes/origin/HEAD, then fetches and resets againstorigin/<branch>explicitly. Falls back tomainiforigin/HEADis not set.How to reproduce
npx bmad-method install --custom-source https://github.com/user/custom-modulemainon the custom module repoRoot cause
git clone --depth 1creates a shallow clone. In shallow clones,origin/HEADis a fixed reference to the initial commit and does not update withgit fetch origin --depth 1. The subsequentgit reset --hard origin/HEADtherefore always resets to the original commit.Fix
Test plan
npm run test:install)main, re-run install, verify cache picks up new commits