Skip to content

Commit

Permalink
feat(git): cloneSubmodulesFilter (#33115)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins authored Dec 18, 2024
1 parent 98693e2 commit e27fe66
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 4 deletions.
10 changes: 9 additions & 1 deletion docs/usage/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,19 @@ For `sbt` note that Renovate will update the version string only for packages th

## cloneSubmodules

Enabling this option will mean that any detected Git submodules will be cloned at time of repository clone.
Enabling this option will mean that detected Git submodules will be cloned at time of repository clone.
By default all will be cloned, but this can be customized by configuring `cloneSubmodulesFilter` too.
Submodules are always cloned recursively.

Important: private submodules aren't supported by Renovate, unless the underlying `ssh` layer already has the correct permissions.

## cloneSubmodulesFilter

Use this option together with `cloneSubmodules` if you wish to clone only a subset of submodules.

This config option supports regex and glob filters, including negative matches.
For more details on this syntax see Renovate's [string pattern matching documentation](./string-pattern-matching.md).

## commitBody

Configure this if you wish Renovate to add a commit body, otherwise Renovate uses a regular single-line commit.
Expand Down
8 changes: 8 additions & 0 deletions lib/config/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2856,6 +2856,14 @@ const options: RenovateOptions[] = [
type: 'boolean',
default: false,
},
{
name: 'cloneSubmodulesFilter',
description:
'List of submodules names or patterns to clone when cloneSubmodules=true.',
type: 'array',
subType: 'string',
default: ['*'],
},
{
name: 'ignorePrAuthor',
description:
Expand Down
1 change: 1 addition & 0 deletions lib/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ export interface RenovateConfig
baseBranch?: string;
defaultBranch?: string;
branchList?: string[];
cloneSubmodulesFilter?: string[];
description?: string | string[];
force?: RenovateConfig;
errors?: ValidationMessage[];
Expand Down
2 changes: 2 additions & 0 deletions lib/modules/platform/azure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export async function getJsonFile(
export async function initRepo({
repository,
cloneSubmodules,
cloneSubmodulesFilter,
}: RepoParams): Promise<RepoResult> {
logger.debug(`initRepo("${repository}")`);
config = { repository } as Config;
Expand Down Expand Up @@ -240,6 +241,7 @@ export async function initRepo({
url,
extraCloneOpts: getStorageExtraCloneOpts(opts),
cloneSubmodules,
cloneSubmodulesFilter,
});
const repoConfig: RepoResult = {
defaultBranch,
Expand Down
2 changes: 2 additions & 0 deletions lib/modules/platform/bitbucket-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export async function getJsonFile(
export async function initRepo({
repository,
cloneSubmodules,
cloneSubmodulesFilter,
ignorePrAuthor,
gitUrl,
}: RepoParams): Promise<RepoResult> {
Expand Down Expand Up @@ -274,6 +275,7 @@ export async function initRepo({
url,
extraCloneOpts: getExtraCloneOpts(opts),
cloneSubmodules,
cloneSubmodulesFilter,
fullClone: semver.lte(defaults.version, '8.0.0'),
});

Expand Down
2 changes: 2 additions & 0 deletions lib/modules/platform/bitbucket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export async function getJsonFile(
export async function initRepo({
repository,
cloneSubmodules,
cloneSubmodulesFilter,
ignorePrAuthor,
bbUseDevelopmentBranch,
}: RepoParams): Promise<RepoResult> {
Expand Down Expand Up @@ -262,6 +263,7 @@ export async function initRepo({
...config,
url,
cloneSubmodules,
cloneSubmodulesFilter,
});
const repoConfig: RepoResult = {
defaultBranch: mainBranch,
Expand Down
3 changes: 3 additions & 0 deletions lib/modules/platform/gitea/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ interface GiteaRepoConfig {
labelList: Promise<Label[]> | null;
defaultBranch: string;
cloneSubmodules: boolean;
cloneSubmodulesFilter: string[] | undefined;
hasIssuesEnabled: boolean;
}

Expand Down Expand Up @@ -255,13 +256,15 @@ const platform: Platform = {
async initRepo({
repository,
cloneSubmodules,
cloneSubmodulesFilter,
gitUrl,
}: RepoParams): Promise<RepoResult> {
let repo: Repo;

config = {} as any;
config.repository = repository;
config.cloneSubmodules = !!cloneSubmodules;
config.cloneSubmodulesFilter = cloneSubmodulesFilter;

// Try to fetch information about repository
try {
Expand Down
2 changes: 2 additions & 0 deletions lib/modules/platform/github/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,13 +447,15 @@ export async function initRepo({
forkToken,
renovateUsername,
cloneSubmodules,
cloneSubmodulesFilter,
ignorePrAuthor,
}: RepoParams): Promise<RepoResult> {
logger.debug(`initRepo("${repository}")`);
// config is used by the platform api itself, not necessary for the app layer to know
config = {
repository,
cloneSubmodules,
cloneSubmodulesFilter,
ignorePrAuthor,
} as any;
// istanbul ignore if
Expand Down
2 changes: 2 additions & 0 deletions lib/modules/platform/gitlab/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ exports[`modules/platform/gitlab/index initRepo should fall back respecting when
[
{
"cloneSubmodules": undefined,
"cloneSubmodulesFilter": undefined,
"defaultBranch": "master",
"ignorePrAuthor": undefined,
"mergeMethod": "merge",
Expand All @@ -150,6 +151,7 @@ exports[`modules/platform/gitlab/index initRepo should use ssh_url_to_repo if gi
[
{
"cloneSubmodules": undefined,
"cloneSubmodulesFilter": undefined,
"defaultBranch": "master",
"ignorePrAuthor": undefined,
"mergeMethod": "merge",
Expand Down
3 changes: 3 additions & 0 deletions lib/modules/platform/gitlab/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ let config: {
mergeMethod: MergeMethod;
defaultBranch: string;
cloneSubmodules: boolean | undefined;
cloneSubmodulesFilter: string[] | undefined;
ignorePrAuthor: boolean | undefined;
squash: boolean;
} = {} as any;
Expand Down Expand Up @@ -299,6 +300,7 @@ function getRepoUrl(
export async function initRepo({
repository,
cloneSubmodules,
cloneSubmodulesFilter,
ignorePrAuthor,
gitUrl,
endpoint,
Expand All @@ -307,6 +309,7 @@ export async function initRepo({
config = {} as any;
config.repository = urlEscape(repository);
config.cloneSubmodules = cloneSubmodules;
config.cloneSubmodulesFilter = cloneSubmodulesFilter;
config.ignorePrAuthor = ignorePrAuthor;

let res: HttpResponse<RepoResponse>;
Expand Down
1 change: 1 addition & 0 deletions lib/modules/platform/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface RepoParams {
forkProcessing?: 'enabled' | 'disabled';
renovateUsername?: string;
cloneSubmodules?: boolean;
cloneSubmodulesFilter?: string[];
ignorePrAuthor?: boolean;
bbUseDevelopmentBranch?: boolean;
includeMirrors?: boolean;
Expand Down
1 change: 1 addition & 0 deletions lib/util/git/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ describe('util/git/index', () => {
await repo.commit('Add submodules');
await git.initRepo({
cloneSubmodules: true,
cloneSubmodulesFilter: ['file'],
url: base.path,
});
await git.syncGit();
Expand Down
15 changes: 13 additions & 2 deletions lib/util/git/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type { GitProtocol } from '../../types/git';
import { incLimitedValue } from '../../workers/global/limits';
import { getCache } from '../cache/repository';
import { newlineRegex, regEx } from '../regex';
import { matchRegexOrGlobList } from '../string-match';
import { parseGitAuthor } from './author';
import {
getCachedBehindBaseResult,
Expand Down Expand Up @@ -344,14 +345,24 @@ export async function getSubmodules(): Promise<string[]> {
}
}

export async function cloneSubmodules(shouldClone: boolean): Promise<void> {
export async function cloneSubmodules(
shouldClone: boolean,
cloneSubmodulesFilter: string[] | undefined,
): Promise<void> {
if (!shouldClone || submodulesInitizialized) {
return;
}
submodulesInitizialized = true;
await syncGit();
const submodules = await getSubmodules();
for (const submodule of submodules) {
if (!matchRegexOrGlobList(submodule, cloneSubmodulesFilter ?? ['*'])) {
logger.debug(
{ cloneSubmodulesFilter },
`Skipping submodule ${submodule}`,
);
continue;
}
try {
logger.debug(`Cloning git submodule at ${submodule}`);
await gitRetry(() =>
Expand Down Expand Up @@ -458,7 +469,7 @@ export async function syncGit(): Promise<void> {
throw err;
}
// This will only happen now if set in global config
await cloneSubmodules(!!config.cloneSubmodules);
await cloneSubmodules(!!config.cloneSubmodules, config.cloneSubmodulesFilter);
try {
const latestCommit = (await git.log({ n: 1 })).latest;
logger.debug({ latestCommit }, 'latest repository commit');
Expand Down
1 change: 1 addition & 0 deletions lib/util/git/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface StorageConfig {
url: string;
extraCloneOpts?: GitOptions;
cloneSubmodules?: boolean;
cloneSubmodulesFilter?: string[];
fullClone?: boolean;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/workers/repository/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ export async function initRepo(
'Full resolved config and hostRules including presets',
);
}
await cloneSubmodules(!!config.cloneSubmodules);
await cloneSubmodules(!!config.cloneSubmodules, config.cloneSubmodulesFilter);
return config;
}

0 comments on commit e27fe66

Please sign in to comment.