Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add git lfs admin option #10748

Closed
wants to merge 13 commits into from
12 changes: 12 additions & 0 deletions docs/usage/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,18 @@ Under the hood, it creates a MR-level approval rule where `approvals_required` i
This option works only when `automerge=true`, `automergeType=pr` and `gitLabAutomerge=true`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This option works only when `automerge=true`, `automergeType=pr` and `gitLabAutomerge=true`.
To use `gitLabIgnoreApprovals` you need to set `automerge=true`, `automergeType=pr` and `gitLabAutomerge=true`.

Maybe this is clearer?

Also, approval rules overriding should not be [prevented in GitLab settings](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/settings.html#prevent-overrides-of-default-approvals).

## gitLfsExclude

See also the `allowGitLfs` and `gitNoVerify` options.

**Note** This is not supported in the WhiteSource Renovate Hosted App.

## gitLfsInclude

See also the `allowGitLfs` and `gitNoVerify` options.

**Note** This is not supported in the WhiteSource Renovate Hosted App.

## golang

Configuration added here applies for all Go-related updates, however currently the only supported package manager for Go is the native Go Modules (the `gomod` manager).
Expand Down
7 changes: 7 additions & 0 deletions docs/usage/self-hosted-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ Please also see [Self-Hosted Experimental Options](./self-hosted-experimental.md

## allowCustomCrateRegistries

## allowGitLfs

**Note** You need to also set the Git commands that Renovate passes to the `gitNoVerify` option.
viceice marked this conversation as resolved.
Show resolved Hide resolved
This way Renovate can commit and push Git LFS objects.
viceice marked this conversation as resolved.
Show resolved Hide resolved

**Note** `allowGitLfs` does not work in the official Renovate docker images, see issue [containerbase/buildpack#13](https://github.com/containerbase/buildpack/issues/13) for more information.

## allowPostUpgradeCommandTemplating

Set to true to allow templating of dependency level post-upgrade commands.
Expand Down
1 change: 1 addition & 0 deletions lib/config/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ let adminConfig: RepoAdminConfig = {};
// TODO: once admin config work is complete, add a test to make sure this list includes all options with admin=true (#9603)
const repoAdminOptions = [
'allowCustomCrateRegistries',
'allowGitLfs',
'allowPostUpgradeCommandTemplating',
'allowScripts',
'allowedPostUpgradeCommands',
Expand Down
20 changes: 20 additions & 0 deletions lib/config/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ import * as pep440Versioning from '../versioning/pep440';
import type { RenovateOptions } from './types';
viceice marked this conversation as resolved.
Show resolved Hide resolved

const options: RenovateOptions[] = [
{
name: 'allowGitLfs',
description: 'If false disallow git-lfs to pull files.',
type: 'boolean',
default: true,
admin: true,
},
{
name: 'allowPostUpgradeCommandTemplating',
description: 'If true allow templating for post-upgrade commands.',
Expand Down Expand Up @@ -2037,6 +2044,19 @@ const options: RenovateOptions[] = [
type: 'boolean',
default: true,
},
{
name: 'gitLfsInclude',
description: 'Which files should be included in git-lfs checkout',
stage: 'repository',
type: 'string',
default: '.yarn,yarn.lock,**/package-lock.json',
},
{
name: 'gitLfsExclude',
description: 'Which files should be excluded in git-lfs checkout',
stage: 'repository',
type: 'string',
},
];

export function getOptions(): RenovateOptions[] {
Expand Down
4 changes: 4 additions & 0 deletions lib/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export interface GlobalOnlyConfig {
// The below should contain config options where admin=true
export interface RepoAdminConfig {
allowCustomCrateRegistries?: boolean;
allowGitLfs?: boolean;
allowPostUpgradeCommandTemplating?: boolean;
allowScripts?: boolean;
allowedPostUpgradeCommands?: string[];
Expand Down Expand Up @@ -167,6 +168,9 @@ export interface RenovateConfig

gitAuthor?: string;

gitLfsInclude?: string;
gitLfsExclude?: string;

hostRules?: HostRule[];

ignorePresets?: string[];
Expand Down
26 changes: 25 additions & 1 deletion lib/util/git/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import URL from 'url';
import is from '@sindresorhus/is';
import fs from 'fs-extra';
import Git, {
DiffResult as DiffResult_,
Expand Down Expand Up @@ -56,6 +57,10 @@ interface LocalConfig extends StorageConfig {
branchCommits: Record<string, CommitSha>;
branchIsModified: Record<string, boolean>;
branchPrefix: string;

gitLfsInclude?: string;
gitLfsExclude?: string;

ignoredAuthors: string[];
}

Expand Down Expand Up @@ -185,6 +190,8 @@ export async function initRepo(args: StorageConfig): Promise<void> {
config.ignoredAuthors = [];
config.additionalBranches = [];
config.branchIsModified = {};
config.gitLfsInclude = undefined;
config.gitLfsExclude = undefined;
const { localDir } = getAdminConfig();
git = Git(localDir);
gitInitialized = false;
Expand Down Expand Up @@ -237,9 +244,13 @@ async function setBranchPrefix(branchPrefix: string): Promise<void> {
export async function setUserRepoConfig({
branchPrefix,
gitIgnoredAuthors,
gitLfsInclude,
gitLfsExclude,
}: RenovateConfig): Promise<void> {
await setBranchPrefix(branchPrefix);
config.ignoredAuthors = gitIgnoredAuthors ?? [];
config.gitLfsInclude = gitLfsInclude;
config.gitLfsExclude = gitLfsExclude;
}

export async function getSubmodules(): Promise<string[]> {
Expand Down Expand Up @@ -267,7 +278,7 @@ export async function syncGit(): Promise<void> {
return;
}
gitInitialized = true;
const { localDir } = getAdminConfig();
const { localDir, allowGitLfs } = getAdminConfig();
logger.debug('Initializing git repository into ' + localDir);
const gitHead = join(localDir, '.git/HEAD');
let clone = true;
Expand Down Expand Up @@ -305,6 +316,19 @@ export async function syncGit(): Promise<void> {
opts.push(e[0], `${e[1]}`)
);
}

// istanbul ignore if
if (allowGitLfs) {
if (is.nonEmptyString(config.gitLfsInclude)) {
opts.push('-c', `lfs.fetchinclude=${config.gitLfsInclude}`);
}
if (is.nonEmptyString(config.gitLfsExclude)) {
opts.push('-c', `lfs.fetchexclude=${config.gitLfsExclude}`);
}
} else {
opts.push('-c', 'lfs.fetchexclude=*');
}

await git.clone(config.url, '.', opts);
} catch (err) /* istanbul ignore next */ {
logger.debug({ err }, 'git clone error');
Expand Down