diff --git a/lib/util/git/index.ts b/lib/util/git/index.ts index 55b466ae0bac6333a4c9b27ed562591043222df5..d357441b6033790e845963befc78e59d736c7af7 100644 --- a/lib/util/git/index.ts +++ b/lib/util/git/index.ts @@ -156,6 +156,7 @@ let config: LocalConfig = {} as any; // TODO: can be undefined let git: SimpleGit; let gitInitialized: boolean; +let submodulesInitizialized: boolean; let privateKeySet = false; @@ -236,6 +237,7 @@ export async function initRepo(args: StorageConfig): Promise<void> { LC_ALL: 'C', }); gitInitialized = false; + submodulesInitizialized = false; await fetchBranchCommits(); } @@ -341,6 +343,26 @@ export async function getSubmodules(): Promise<string[]> { } } +export async function cloneSubmodules(shouldClone: boolean): Promise<void> { + if (!shouldClone || submodulesInitizialized) { + return; + } + submodulesInitizialized = true; + await syncGit(); + const submodules = await getSubmodules(); + for (const submodule of submodules) { + try { + logger.debug(`Cloning git submodule at ${submodule}`); + await gitRetry(() => git.submoduleUpdate(['--init', submodule])); + } catch (err) { + logger.warn( + { err }, + `Unable to initialise git submodule at ${submodule}` + ); + } + } +} + export async function syncGit(): Promise<void> { if (gitInitialized) { return; @@ -415,20 +437,8 @@ export async function syncGit(): Promise<void> { } throw err; } - if (config.cloneSubmodules) { - const submodules = await getSubmodules(); - for (const submodule of submodules) { - try { - logger.debug(`Cloning git submodule at ${submodule}`); - await gitRetry(() => git.submoduleUpdate(['--init', submodule])); - } catch (err) { - logger.warn( - { err }, - `Unable to initialise git submodule at ${submodule}` - ); - } - } - } + // This will only happen now if set in global config + await cloneSubmodules(!!config.cloneSubmodules); try { const latestCommit = (await git.log({ n: 1 })).latest; logger.debug({ latestCommit }, 'latest repository commit'); diff --git a/lib/workers/repository/init/index.ts b/lib/workers/repository/init/index.ts index 199e3330f99f7e338c785b16a9628ecc3b2d8d30..c07d0ef73b91000bd6c3bf6776b86ff4837145b5 100644 --- a/lib/workers/repository/init/index.ts +++ b/lib/workers/repository/init/index.ts @@ -4,7 +4,7 @@ import type { RenovateConfig } from '../../../config/types'; import { logger } from '../../../logger'; import { platform } from '../../../modules/platform'; import { clone } from '../../../util/clone'; -import { setUserRepoConfig } from '../../../util/git'; +import { cloneSubmodules, setUserRepoConfig } from '../../../util/git'; import { getAll } from '../../../util/host-rules'; import { checkIfConfigured } from '../configured'; import { PackageFiles } from '../package-files'; @@ -48,5 +48,6 @@ export async function initRepo( 'Full resolved config and hostRules including presets' ); } + await cloneSubmodules(!!config.cloneSubmodules); return config; }