mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-24 14:34:21 +00:00
d1fd5df4bc
* build(deps): update dependency simple-git to v4 [security] | datasource | package | from | to | | ---------- | ---------- | ------ | ----- | | npm | simple-git | 3.36.0 | 4.0.1 | * fix(git): adapt to simple-git v4 environment guard Allow the environment Renovate passes explicitly, use a dedicated instance for authenticated submodule updates and allow url.insteadOf rewrites used by host rules authentication. * fix(deps): override @simple-git/argv-parser to v2.0.1 --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: secustor <sebastian@poxhofer.at>
88 lines
2.6 KiB
TypeScript
88 lines
2.6 KiB
TypeScript
import { isArray, isNumber, isString } from '@sindresorhus/is';
|
|
import type { SimpleGitOptions } from 'simple-git';
|
|
import { GlobalConfig } from '../../config/global.ts';
|
|
import { logger } from '../../logger/index.ts';
|
|
import { getEnv } from '../env.ts';
|
|
import type { ResolvedChildEnv } from '../exec/utils.ts';
|
|
import type { GitNoVerifyOption } from './types.ts';
|
|
|
|
let noVerify: GitNoVerifyOption[] = ['push', 'commit'];
|
|
|
|
export function setNoVerify(value: GitNoVerifyOption[]): void {
|
|
if (!isArray(value, isString)) {
|
|
throw new Error('config error: gitNoVerify should be an array of strings');
|
|
}
|
|
noVerify = value;
|
|
}
|
|
|
|
export function getNoVerify(): GitNoVerifyOption[] {
|
|
return noVerify;
|
|
}
|
|
|
|
export function simpleGitConfig(): Partial<SimpleGitOptions> {
|
|
const unsafe: SimpleGitOptions['unsafe'] = {
|
|
allowUnsafeSshCommand: true, // For custom `GIT_SSH_COMMAND`.
|
|
allowUnsafeConfigEnvCount: true, // For custom `GIT_CONFIG_COUNT`, `GIT_CONFIG_KEY_*` and `GIT_CONFIG_VALUE_*`.
|
|
allowUnsafeAskPass: true, // For custom `GIT_ASKPASS`
|
|
allowUnsafeUrlRewrite: true, // For `url.*.insteadOf` set by host rules authentication.
|
|
};
|
|
if (getEnv().RENOVATE_X_CLEAR_HOOKS) {
|
|
unsafe.allowUnsafeHooksPath = true;
|
|
}
|
|
|
|
const config: Partial<SimpleGitOptions> = {
|
|
completion: {
|
|
onClose: true,
|
|
onExit: false,
|
|
},
|
|
config: ['core.quotePath=false'],
|
|
unsafe,
|
|
};
|
|
|
|
// https://github.com/steveukx/git-js/pull/591
|
|
const gitTimeout = GlobalConfig.get('gitTimeout');
|
|
if (isNumber(gitTimeout) && gitTimeout > 0) {
|
|
config.timeout = { block: gitTimeout };
|
|
}
|
|
return config;
|
|
}
|
|
|
|
export interface GitConfigEntry {
|
|
key: string;
|
|
value: string;
|
|
}
|
|
|
|
export function addGitConfigEnvironmentVariables(
|
|
environment: Readonly<ResolvedChildEnv>,
|
|
entries: readonly GitConfigEntry[],
|
|
): ResolvedChildEnv {
|
|
let gitConfigCount = getGitConfigCount(environment.GIT_CONFIG_COUNT);
|
|
const newEnvironment = { ...environment };
|
|
|
|
for (const entry of entries) {
|
|
newEnvironment[`GIT_CONFIG_KEY_${gitConfigCount}`] = entry.key;
|
|
newEnvironment[`GIT_CONFIG_VALUE_${gitConfigCount}`] = entry.value;
|
|
gitConfigCount++;
|
|
}
|
|
newEnvironment.GIT_CONFIG_COUNT = gitConfigCount.toString();
|
|
|
|
return newEnvironment;
|
|
}
|
|
|
|
function getGitConfigCount(value: string | undefined): number {
|
|
if (!value) {
|
|
return 0;
|
|
}
|
|
|
|
const gitConfigCount = parseInt(value, 10);
|
|
if (Number.isNaN(gitConfigCount)) {
|
|
logger.warn(
|
|
{ GIT_CONFIG_COUNT: value },
|
|
`Found GIT_CONFIG_COUNT env variable, but could not parse the value to an integer. Ignoring it.`,
|
|
);
|
|
return 0;
|
|
}
|
|
|
|
return gitConfigCount;
|
|
}
|