From 4d39db528a3ef13d9c103758c9a09664ba0ed8a1 Mon Sep 17 00:00:00 2001 From: Jerome Revillard Date: Mon, 27 Apr 2026 08:34:56 +0200 Subject: [PATCH] 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/` explicitly. Falls back to `main` if origin/HEAD is not set. --- .../modules/custom-module-manager.js | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tools/installer/modules/custom-module-manager.js b/tools/installer/modules/custom-module-manager.js index 9dd9e8b6d..40fd877d5 100644 --- a/tools/installer/modules/custom-module-manager.js +++ b/tools/installer/modules/custom-module-manager.js @@ -424,7 +424,27 @@ class CustomModuleManager { stdio: ['ignore', 'pipe', 'pipe'], }); } else { - execSync('git reset --hard origin/HEAD', { + // Resolve the default branch (origin/HEAD) and fetch it explicitly. + // With shallow clones, `origin/HEAD` is stale and `git reset --hard + // origin/HEAD` never picks up new commits on the default branch. + let defaultBranch = 'main'; + try { + defaultBranch = execSync('git symbolic-ref refs/remotes/origin/HEAD --short', { + cwd: repoCacheDir, + stdio: 'pipe', + }) + .toString() + .trim() + .replace('origin/', ''); + } catch { + // Fallback if origin/HEAD is not set + } + execSync(`git fetch --depth 1 origin ${quoteCustomRef(defaultBranch)}`, { + cwd: repoCacheDir, + stdio: ['ignore', 'pipe', 'pipe'], + env: { ...process.env, GIT_TERMINAL_PROMPT: '0' }, + }); + execSync(`git reset --hard origin/${quoteCustomRef(defaultBranch)}`, { cwd: repoCacheDir, stdio: ['ignore', 'pipe', 'pipe'], });