diff --git a/lib/workers/repository/update/branch/reuse.spec.ts b/lib/workers/repository/update/branch/reuse.spec.ts index 8f47e9782763ed..d5113d962ab7a5 100644 --- a/lib/workers/repository/update/branch/reuse.spec.ts +++ b/lib/workers/repository/update/branch/reuse.spec.ts @@ -262,5 +262,15 @@ describe('workers/repository/update/branch/reuse', () => { expect(config.rebaseWhen).toBe('auto'); expect(result.rebaseWhen).toBe('conflicted'); }); + + it('converts rebaseWhen=auto to behind-base-branch if automerge is true AND branch is new', async () => { + config.rebaseWhen = 'auto'; + config.automerge = true; + scm.branchExists.mockResolvedValueOnce(false); + scm.isBranchBehindBase.mockResolvedValueOnce(false); + const result = await shouldReuseExistingBranch(config); + expect(config.rebaseWhen).toBe('auto'); + expect(result.rebaseWhen).toBe('behind-base-branch'); + }); }); }); diff --git a/lib/workers/repository/update/branch/reuse.ts b/lib/workers/repository/update/branch/reuse.ts index 9a915480b9008b..7b052eeebf1ad9 100644 --- a/lib/workers/repository/update/branch/reuse.ts +++ b/lib/workers/repository/update/branch/reuse.ts @@ -31,14 +31,16 @@ export async function shouldReuseExistingBranch( ): Promise { const { baseBranch, branchName } = config; const result: BranchConfig = { ...config, reuseExistingBranch: false }; + + const keepUpdated = await shouldKeepUpdated(result, baseBranch, branchName); + await determineRebaseWhenValue(result, keepUpdated); + // Check if branch exists if (!(await scm.branchExists(branchName))) { logger.debug(`Branch needs creating`); return result; } logger.debug(`Branch already exists`); - const keepUpdated = await shouldKeepUpdated(result, baseBranch, branchName); - await determineRebaseWhenValue(result, keepUpdated); if (result.rebaseWhen === 'behind-base-branch' || keepUpdated) { if (await scm.isBranchBehindBase(branchName, baseBranch)) {