diff --git a/lib/workers/branch/reuse.spec.ts b/lib/workers/branch/reuse.spec.ts index 0d60da376f7cd1b97f46845fecc51dd8d00b78ca..762ed32024f07d91aed857730fc7f70839ac5328 100644 --- a/lib/workers/branch/reuse.spec.ts +++ b/lib/workers/branch/reuse.spec.ts @@ -159,15 +159,13 @@ describe(getName(__filename), () => { expect(git.isBranchModified).not.toHaveBeenCalled(); }); - it('returns false if automerge, rebaseWhen=conflicted and stale', async () => { + it('returns true if automerge, rebaseWhen=conflicted and stale', async () => { config.rebaseWhen = 'conflicted'; config.automerge = true; git.branchExists.mockReturnValueOnce(true); git.isBranchStale.mockResolvedValueOnce(true); const res = await shouldReuseExistingBranch(config); - expect(res.reuseExistingBranch).toBe(false); - expect(git.isBranchStale).toHaveBeenCalled(); - expect(git.isBranchModified).toHaveBeenCalled(); + expect(res.reuseExistingBranch).toBe(true); }); }); }); diff --git a/lib/workers/branch/reuse.ts b/lib/workers/branch/reuse.ts index 33e7663dd3c4519bc6311cf6c1f5a1d17fd8d269..c105d1f2034581dde82de9b31b0ebead6ed54bfd 100644 --- a/lib/workers/branch/reuse.ts +++ b/lib/workers/branch/reuse.ts @@ -48,8 +48,8 @@ export async function shouldReuseExistingBranch( if ( config.rebaseWhen === 'behind-base-branch' || - (config.rebaseWhen !== 'never' && config.automerge === true) || - (config.rebaseWhen === 'auto' && (await platform.getRepoForceRebase())) + (config.rebaseWhen === 'auto' && + (config.automerge || (await platform.getRepoForceRebase()))) ) { if (await isBranchStale(branchName)) { logger.debug(`Branch is stale and needs rebasing`); @@ -63,7 +63,9 @@ export async function shouldReuseExistingBranch( } logger.debug('Branch is up-to-date'); } else { - logger.debug('Skipping stale branch check'); + logger.debug( + `Skipping stale branch check due to rebaseWhen=${config.rebaseWhen}` + ); } // Now check if PR is unmergeable. If so then we also rebase