diff --git a/lib/platform/git/storage.ts b/lib/platform/git/storage.ts index 82c039dd995fc230ea8119423efd3cf2fdeaf76f..2f8bfe4133bae1e6017747ed7aa66725e0404958 100644 --- a/lib/platform/git/storage.ts +++ b/lib/platform/git/storage.ts @@ -184,14 +184,30 @@ class Storage { if (branchName) { logger.debug(`Setting baseBranch to ${branchName}`); this._config.baseBranch = branchName; - if (branchName !== 'master') { - this._config.baseBranchSha = (await this._git!.raw([ - 'rev-parse', - 'origin/' + branchName, - ])).trim(); + try { + if (branchName !== 'master') { + this._config.baseBranchSha = (await this._git!.raw([ + 'rev-parse', + 'origin/' + branchName, + ])).trim(); + } + await this._git!.checkout([branchName, '-f']); + await this._git!.reset('hard'); + } catch (err) /* istanbul ignore next */ { + if ( + err.message.includes( + 'unknown revision or path not in the working tree' + ) + ) { + const error = new Error('config-validation'); + error.validationError = 'baseBranch not found'; + error.validationMessage = + 'The following configured baseBranch could not be found: ' + + branchName; + throw error; + } + throw err; } - await this._git!.checkout([branchName, '-f']); - await this._git!.reset('hard'); } } diff --git a/lib/types.d.ts b/lib/types.d.ts index 331a2b54c8b16ea0826c8ea7122f41c406d2d7f7..4df000bb6b8c5b636aec79bef5d316c952876b5f 100644 --- a/lib/types.d.ts +++ b/lib/types.d.ts @@ -15,6 +15,11 @@ declare namespace Renovate { declare var logger: Renovate.ILogger; +declare interface Error { + validationError?: string; + validationMessage?: string; +} + declare namespace NodeJS { interface Global { gitAuthor?: { name: string; email: string };