0
0
Fork 0
mirror of https://github.com/renovatebot/renovate.git synced 2025-01-11 13:48:55 +00:00
renovatebot_renovate/lib/modules/manager/git-submodules/update.ts
Zigmas Bitinas 13d9c51a13
fix(manager/git-submodule): updates when update=none (#32455)
Co-authored-by: Rhys Arkins <rhys@arkins.net>
2024-11-28 17:43:03 +00:00

48 lines
1.5 KiB
TypeScript

import Git from 'simple-git';
import upath from 'upath';
import { GlobalConfig } from '../../../config/global';
import { logger } from '../../../logger';
import { readLocalFile } from '../../../util/fs';
import { getGitEnvironmentVariables } from '../../../util/git/auth';
import type { UpdateDependencyConfig } from '../types';
export default async function updateDependency({
fileContent,
upgrade,
}: UpdateDependencyConfig): Promise<string | null> {
const localDir = GlobalConfig.get('localDir');
const gitSubmoduleAuthEnvironmentVariables = getGitEnvironmentVariables([
'git-tags',
'git-refs',
]);
const gitEnv = {
// pass all existing env variables
...process.env,
// add all known git Variables
...gitSubmoduleAuthEnvironmentVariables,
};
const git = Git(localDir).env(gitEnv);
const submoduleGit = Git(upath.join(localDir, upgrade.depName));
try {
await git.submoduleUpdate(['--checkout', '--init', 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;
}
}