Skip to content

Commit

Permalink
fix: rebase if automerging even if rebaseWhen=conflicted (#8796)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Feb 22, 2021
1 parent 4b62acc commit 8e7e41f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
9 changes: 5 additions & 4 deletions lib/workers/branch/reuse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
7 changes: 5 additions & 2 deletions lib/workers/branch/reuse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand All @@ -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
Expand Down

0 comments on commit 8e7e41f

Please sign in to comment.