Files
renovate/lib/modules/manager/git-submodules/update.ts
Gursewak Mangat bbd603e277 fix(manager/git-submodules): init nested submodules in updateDependency (#45606)
fix(git-submodules): init nested submodules in updateDependency

The cloneSubmodules function already uses --init --recursive, but
updateDependency only uses --checkout --init, losing nested submodule
content after updates. This breaks postUpgradeTasks that depend on
files inside nested submodules.

For repos without nested submodules, --recursive is a no-op.
2026-09-02 08:59:52 +00:00

55 lines
1.5 KiB
TypeScript

import upath from 'upath';
import { GlobalConfig } from '../../../config/global.ts';
import { logger } from '../../../logger/index.ts';
import { readLocalFile } from '../../../util/fs/index.ts';
import { createSimpleGit } from '../../../util/git/index.ts';
import type { UpdateDependencyConfig } from '../types.ts';
export default async function updateDependency({
fileContent,
upgrade,
}: UpdateDependencyConfig): Promise<string | null> {
// TODO: types (#22198)
const localDir = GlobalConfig.get('localDir');
const authentication = {
hostTypes: ['git-tags', 'git-refs'],
};
const git = createSimpleGit({
config: { baseDir: localDir },
authentication,
});
const submoduleGit = createSimpleGit({
// TODO: types (#22198)
config: { baseDir: upath.join(localDir, upgrade.depName!) },
authentication,
});
try {
await git.submoduleUpdate([
'--checkout',
'--init',
'--recursive',
upgrade.depName!,
]);
await submoduleGit.checkout([upgrade.newDigest!]);
if (upgrade.newValue && upgrade.currentValue !== upgrade.newValue) {
await git.subModule([
'set-branch',
'--branch',
upgrade.newValue,
upgrade.depName!,
]);
const updatedPackageContent = await readLocalFile(
upgrade.packageFile!,
'utf8',
);
return updatedPackageContent!;
}
return fileContent;
} catch (err) {
logger.debug({ err }, 'submodule checkout error');
return null;
}
}