diff --git a/lib/workers/branch/reuse.spec.ts b/lib/workers/branch/reuse.spec.ts index 29564f113dccbccefb61bbf2c5df2bbd058b47da..0d60da376f7cd1b97f46845fecc51dd8d00b78ca 100644 --- a/lib/workers/branch/reuse.spec.ts +++ b/lib/workers/branch/reuse.spec.ts @@ -159,14 +159,15 @@ describe(getName(__filename), () => { expect(git.isBranchModified).not.toHaveBeenCalled(); }); - it('returns true if automerge, rebaseWhen=conflicted and stale', async () => { + it('returns false 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(true); - expect(git.isBranchStale).not.toHaveBeenCalled(); - expect(git.isBranchModified).not.toHaveBeenCalled(); + expect(res.reuseExistingBranch).toBe(false); + expect(git.isBranchStale).toHaveBeenCalled(); + expect(git.isBranchModified).toHaveBeenCalled(); }); }); }); diff --git a/lib/workers/branch/reuse.ts b/lib/workers/branch/reuse.ts index 965188cfd6e0c177572fd187a310f8ceaef6c2d7..33e7663dd3c4519bc6311cf6c1f5a1d17fd8d269 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 === 'auto' && - (config.automerge === true || (await platform.getRepoForceRebase()))) + (config.rebaseWhen !== 'never' && config.automerge === true) || + (config.rebaseWhen === 'auto' && (await platform.getRepoForceRebase())) ) { if (await isBranchStale(branchName)) { logger.debug(`Branch is stale and needs rebasing`); @@ -61,6 +61,9 @@ export async function shouldReuseExistingBranch( } return { reuseExistingBranch: false }; } + logger.debug('Branch is up-to-date'); + } else { + logger.debug('Skipping stale branch check'); } // Now check if PR is unmergeable. If so then we also rebase