Skip to content

Commit f9fd7ae

Browse files
committed
fix: resolve default branch explicitly when updating shallow-cloned custom 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.
1 parent 48a7ec8 commit f9fd7ae

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

tools/installer/modules/custom-module-manager.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,27 @@ class CustomModuleManager {
380380
stdio: ['ignore', 'pipe', 'pipe'],
381381
});
382382
} else {
383-
execSync('git reset --hard origin/HEAD', {
383+
// Resolve the default branch (origin/HEAD) and fetch it explicitly.
384+
// With shallow clones, `origin/HEAD` is stale and `git reset --hard
385+
// origin/HEAD` never picks up new commits on the default branch.
386+
let defaultBranch = 'main';
387+
try {
388+
defaultBranch = execSync('git symbolic-ref refs/remotes/origin/HEAD --short', {
389+
cwd: repoCacheDir,
390+
stdio: 'pipe',
391+
})
392+
.toString()
393+
.trim()
394+
.replace('origin/', '');
395+
} catch {
396+
// Fallback if origin/HEAD is not set
397+
}
398+
execSync(`git fetch --depth 1 origin ${quoteCustomRef(defaultBranch)}`, {
399+
cwd: repoCacheDir,
400+
stdio: ['ignore', 'pipe', 'pipe'],
401+
env: { ...process.env, GIT_TERMINAL_PROMPT: '0' },
402+
});
403+
execSync(`git reset --hard origin/${quoteCustomRef(defaultBranch)}`, {
384404
cwd: repoCacheDir,
385405
stdio: ['ignore', 'pipe', 'pipe'],
386406
});

0 commit comments

Comments
 (0)