Skip to content

Commit 613df10

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 6ff74ba commit 613df10

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

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

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

0 commit comments

Comments
 (0)