diff --git a/lib/platform/azure/index.ts b/lib/platform/azure/index.ts index 4dc108915a1e0a..f2e24997fbef57 100644 --- a/lib/platform/azure/index.ts +++ b/lib/platform/azure/index.ts @@ -169,6 +169,8 @@ export async function initRepo({ localDir, url, extraCloneOpts: azureHelper.getStorageExtraCloneOpts(opts), + gitAuthorName: global.gitAuthor?.name, + gitAuthorEmail: global.gitAuthor?.email, }); const repoConfig: RepoConfig = { baseBranch: config.baseBranch, diff --git a/lib/platform/bitbucket-server/index.ts b/lib/platform/bitbucket-server/index.ts index 83d32dceee9d1f..3dbf30082c510c 100644 --- a/lib/platform/bitbucket-server/index.ts +++ b/lib/platform/bitbucket-server/index.ts @@ -191,6 +191,8 @@ export async function initRepo({ ...config, localDir, url: gitUrl, + gitAuthorName: global.gitAuthor?.name, + gitAuthorEmail: global.gitAuthor?.email, }); try { diff --git a/lib/platform/bitbucket/index.ts b/lib/platform/bitbucket/index.ts index 61552d83dabf0f..cd5b87a0f3187a 100644 --- a/lib/platform/bitbucket/index.ts +++ b/lib/platform/bitbucket/index.ts @@ -160,6 +160,8 @@ export async function initRepo({ ...config, localDir, url, + gitAuthorName: global.gitAuthor?.name, + gitAuthorEmail: global.gitAuthor?.email, }); const repoConfig: RepoConfig = { baseBranch: config.baseBranch, diff --git a/lib/platform/git/storage.spec.ts b/lib/platform/git/storage.spec.ts index 1966fe7ba3e042..7e1efd4a935c1c 100644 --- a/lib/platform/git/storage.spec.ts +++ b/lib/platform/git/storage.spec.ts @@ -47,16 +47,14 @@ describe('platform/git/storage', () => { const repo = Git(origin.path); await repo.clone(base.path, '.', ['--bare']); tmpDir = await tmp.dir({ unsafeCleanup: true }); - global.gitAuthor = { - name: 'test', - email: 'test@example.com', - }; await git.initRepo({ localDir: tmpDir.path, url: origin.path, extraCloneOpts: { '--config': 'extra.clone.config=test-extra-config-value', }, + gitAuthorName: 'test', + gitAuthorEmail: 'test@example.com', }); }); diff --git a/lib/platform/git/storage.ts b/lib/platform/git/storage.ts index aa9e3ec0c1ff98..0cc66884affc17 100644 --- a/lib/platform/git/storage.ts +++ b/lib/platform/git/storage.ts @@ -28,6 +28,8 @@ interface StorageConfig { baseBranch?: string; url: string; extraCloneOpts?: Git.Options; + gitAuthorName?: string; + gitAuthorEmail?: string; } interface LocalConfig extends StorageConfig { @@ -200,16 +202,20 @@ export class Storage { } logger.warn({ err }, 'Cannot retrieve latest commit date'); } - if (global.gitAuthor) { - logger.debug({ gitAuthor: global.gitAuthor }, 'Setting git author'); - try { - await this._git.raw(['config', 'user.name', global.gitAuthor.name]); - await this._git.raw(['config', 'user.email', global.gitAuthor.email]); - } catch (err) /* istanbul ignore next */ { - checkForPlatformFailure(err); - logger.debug({ err }, 'Error setting git config'); - throw new Error(REPOSITORY_TEMPORARY_ERROR); + try { + const { gitAuthorName, gitAuthorEmail } = args; + if (gitAuthorName) { + logger.debug({ gitAuthorName }, 'Setting git author name'); + await this._git.raw(['config', 'user.name', gitAuthorName]); } + if (gitAuthorEmail) { + logger.debug({ gitAuthorEmail }, 'Setting git author email'); + await this._git.raw(['config', 'user.email', gitAuthorEmail]); + } + } catch (err) /* istanbul ignore next */ { + checkForPlatformFailure(err); + logger.debug({ err }, 'Error setting git author config'); + throw new Error(REPOSITORY_TEMPORARY_ERROR); } await setBaseBranchToDefault(this._git); diff --git a/lib/platform/gitea/index.ts b/lib/platform/gitea/index.ts index 2fea422ce91b7b..5a394fbbf34b8b 100644 --- a/lib/platform/gitea/index.ts +++ b/lib/platform/gitea/index.ts @@ -338,6 +338,8 @@ const platform: Platform = { await config.storage.initRepo({ ...config, url: URL.format(gitEndpoint), + gitAuthorName: global.gitAuthor?.name, + gitAuthorEmail: global.gitAuthor?.email, }); // Reset cached resources diff --git a/lib/platform/github/index.ts b/lib/platform/github/index.ts index d23dc10cbb3ad0..d45a87d29a569a 100644 --- a/lib/platform/github/index.ts +++ b/lib/platform/github/index.ts @@ -436,6 +436,8 @@ export async function initRepo({ await config.storage.initRepo({ ...config, url, + gitAuthorName: global.gitAuthor?.name, + gitAuthorEmail: global.gitAuthor?.email, }); const repoConfig: RepoConfig = { baseBranch: config.baseBranch, diff --git a/lib/platform/gitlab/index.ts b/lib/platform/gitlab/index.ts index e7e5b37a40666d..f3b61624f57f93 100644 --- a/lib/platform/gitlab/index.ts +++ b/lib/platform/gitlab/index.ts @@ -249,6 +249,8 @@ export async function initRepo({ await config.storage.initRepo({ ...config, url, + gitAuthorName: global.gitAuthor?.name, + gitAuthorEmail: global.gitAuthor?.email, }); } catch (err) /* istanbul ignore next */ { logger.debug({ err }, 'Caught initRepo error');