Skip to content

Commit 9443c7f

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 9443c7f

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
@@ -379,7 +379,27 @@ 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+
})
391+
.toString()
392+
.trim()
393+
.replace('origin/', '');
394+
} catch {
395+
// Fallback if origin/HEAD is not set
396+
}
397+
execSync(`git fetch --depth 1 origin ${quoteCustomRef(defaultBranch)}`, {
398+
cwd: repoCacheDir,
399+
stdio: ['ignore', 'pipe', 'pipe'],
400+
env: { ...process.env, GIT_TERMINAL_PROMPT: '0' },
401+
});
402+
execSync(`git reset --hard origin/${quoteCustomRef(defaultBranch)}`, {
383403
cwd: repoCacheDir,
384404
stdio: ['ignore', 'pipe', 'pipe'],
385405
});

0 commit comments

Comments
 (0)