From 26fd21cd53251e84c76fbc215ad5473c9ba38675 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Fri, 15 May 2020 12:45:03 +0200
Subject: [PATCH] refactor: parentBranch -> reuseExistingBranch (#6236)

---
 lib/manager/common.ts                         |  2 +-
 lib/manager/npm/post-update/index.ts          | 10 ++--
 .../__snapshots__/get-updated.spec.ts.snap    | 20 ++++----
 lib/workers/branch/auto-replace.spec.ts       | 34 ++++++++-----
 lib/workers/branch/auto-replace.ts            |  4 +-
 lib/workers/branch/get-updated.spec.ts        | 12 ++---
 lib/workers/branch/get-updated.ts             | 48 ++++++++++--------
 lib/workers/branch/index.spec.ts              | 18 +++----
 lib/workers/branch/index.ts                   |  8 +--
 lib/workers/branch/lock-files/index.spec.ts   |  2 +-
 .../branch/{parent.spec.ts => reuse.spec.ts}  | 50 +++++++++----------
 lib/workers/branch/{parent.ts => reuse.ts}    | 27 +++++-----
 lib/workers/common.ts                         |  2 +-
 13 files changed, 126 insertions(+), 111 deletions(-)
 rename lib/workers/branch/{parent.spec.ts => reuse.spec.ts} (73%)
 rename lib/workers/branch/{parent.ts => reuse.ts} (77%)

diff --git a/lib/manager/common.ts b/lib/manager/common.ts
index 044a508567..a9acb45d7d 100644
--- a/lib/manager/common.ts
+++ b/lib/manager/common.ts
@@ -259,5 +259,5 @@ export interface PostUpdateConfig extends ManagerConfig, Record<string, any> {
   npmLock?: string;
   yarnLock?: string;
   branchName?: string;
-  parentBranch?: string;
+  reuseExistingBranch?: boolean;
 }
diff --git a/lib/manager/npm/post-update/index.ts b/lib/manager/npm/post-update/index.ts
index 9a47355d23..2dd31ea3e9 100644
--- a/lib/manager/npm/post-update/index.ts
+++ b/lib/manager/npm/post-update/index.ts
@@ -360,7 +360,7 @@ export async function getAdditionalFiles(
   logger.debug('Getting updated lock files');
   if (
     config.updateType === 'lockFileMaintenance' &&
-    config.parentBranch &&
+    config.reuseExistingBranch &&
     (await platform.branchExists(config.branchName))
   ) {
     logger.debug('Skipping lockFileMaintenance update');
@@ -466,7 +466,7 @@ export async function getAdditionalFiles(
     } else {
       const existingContent = await platform.getFile(
         lockFile,
-        config.parentBranch
+        config.reuseExistingBranch ? config.branchName : config.baseBranch
       );
       if (res.lockFile !== existingContent) {
         logger.debug(`${lockFile} needs updating`);
@@ -531,7 +531,7 @@ export async function getAdditionalFiles(
     } else {
       const existingContent = await platform.getFile(
         lockFileName,
-        config.parentBranch
+        config.reuseExistingBranch ? config.branchName : config.baseBranch
       );
       if (res.lockFile !== existingContent) {
         logger.debug('yarn.lock needs updating');
@@ -628,7 +628,7 @@ export async function getAdditionalFiles(
     } else {
       const existingContent = await platform.getFile(
         lockFile,
-        config.parentBranch
+        config.reuseExistingBranch ? config.branchName : config.baseBranch
       );
       if (res.lockFile !== existingContent) {
         logger.debug('pnpm-lock.yaml needs updating');
@@ -724,7 +724,7 @@ export async function getAdditionalFiles(
         logger.trace('Checking for ' + filename);
         const existingContent = await platform.getFile(
           filename,
-          config.parentBranch
+          config.reuseExistingBranch ? config.branchName : config.baseBranch
         );
         if (existingContent) {
           logger.trace('Found lock file');
diff --git a/lib/workers/branch/__snapshots__/get-updated.spec.ts.snap b/lib/workers/branch/__snapshots__/get-updated.spec.ts.snap
index 135fa33f2b..e751ab26d1 100644
--- a/lib/workers/branch/__snapshots__/get-updated.spec.ts.snap
+++ b/lib/workers/branch/__snapshots__/get-updated.spec.ts.snap
@@ -3,7 +3,7 @@
 exports[`workers/branch/get-updated getUpdatedPackageFiles() handles autoreplace base updated 1`] = `
 Object {
   "artifactErrors": Array [],
-  "parentBranch": undefined,
+  "reuseExistingBranch": undefined,
   "updatedArtifacts": Array [],
   "updatedPackageFiles": Array [
     Object {
@@ -17,7 +17,7 @@ Object {
 exports[`workers/branch/get-updated getUpdatedPackageFiles() handles autoreplace branch needs update 1`] = `
 Object {
   "artifactErrors": Array [],
-  "parentBranch": undefined,
+  "reuseExistingBranch": false,
   "updatedArtifacts": Array [],
   "updatedPackageFiles": Array [
     Object {
@@ -31,7 +31,7 @@ Object {
 exports[`workers/branch/get-updated getUpdatedPackageFiles() handles autoreplace branch no update 1`] = `
 Object {
   "artifactErrors": Array [],
-  "parentBranch": undefined,
+  "reuseExistingBranch": undefined,
   "updatedArtifacts": Array [],
   "updatedPackageFiles": Array [],
 }
@@ -40,7 +40,7 @@ Object {
 exports[`workers/branch/get-updated getUpdatedPackageFiles() handles content change 1`] = `
 Object {
   "artifactErrors": Array [],
-  "parentBranch": undefined,
+  "reuseExistingBranch": false,
   "updatedArtifacts": Array [],
   "updatedPackageFiles": Array [
     Object {
@@ -54,7 +54,7 @@ Object {
 exports[`workers/branch/get-updated getUpdatedPackageFiles() handles empty 1`] = `
 Object {
   "artifactErrors": Array [],
-  "parentBranch": undefined,
+  "reuseExistingBranch": undefined,
   "updatedArtifacts": Array [],
   "updatedPackageFiles": Array [],
 }
@@ -63,7 +63,7 @@ Object {
 exports[`workers/branch/get-updated getUpdatedPackageFiles() handles git submodules 1`] = `
 Object {
   "artifactErrors": Array [],
-  "parentBranch": undefined,
+  "reuseExistingBranch": undefined,
   "updatedArtifacts": Array [],
   "updatedPackageFiles": Array [
     Object {
@@ -82,7 +82,7 @@ Object {
       "stderr": "some error",
     },
   ],
-  "parentBranch": "some-branch",
+  "reuseExistingBranch": true,
   "updatedArtifacts": Array [],
   "updatedPackageFiles": Array [
     Object {
@@ -96,7 +96,7 @@ Object {
 exports[`workers/branch/get-updated getUpdatedPackageFiles() handles lock files 1`] = `
 Object {
   "artifactErrors": Array [],
-  "parentBranch": "some-branch",
+  "reuseExistingBranch": true,
   "updatedArtifacts": Array [
     Object {
       "contents": "some contents",
@@ -115,7 +115,7 @@ Object {
 exports[`workers/branch/get-updated getUpdatedPackageFiles() handles lockFileMaintenance 1`] = `
 Object {
   "artifactErrors": Array [],
-  "parentBranch": undefined,
+  "reuseExistingBranch": undefined,
   "updatedArtifacts": Array [
     Object {
       "contents": "some contents",
@@ -134,7 +134,7 @@ Object {
       "stderr": "some error",
     },
   ],
-  "parentBranch": undefined,
+  "reuseExistingBranch": undefined,
   "updatedArtifacts": Array [],
   "updatedPackageFiles": Array [],
 }
diff --git a/lib/workers/branch/auto-replace.spec.ts b/lib/workers/branch/auto-replace.spec.ts
index bd0ee1f139..3ab53b7745 100644
--- a/lib/workers/branch/auto-replace.spec.ts
+++ b/lib/workers/branch/auto-replace.spec.ts
@@ -14,30 +14,30 @@ jest.mock('../../util/fs');
 
 describe('workers/branch/auto-replace', () => {
   describe('doAutoReplace', () => {
-    let parentBranch: string;
+    let reuseExistingBranch: boolean;
     let upgrade: BranchUpgradeConfig;
     beforeEach(() => {
       upgrade = {
         ...JSON.parse(JSON.stringify(defaultConfig)),
         manager: 'html',
       };
-      parentBranch = undefined;
+      reuseExistingBranch = false;
     });
     it('rebases if the deps list has changed', async () => {
       upgrade.baseDeps = extractPackageFile(sampleHtml).deps;
-      parentBranch = 'some existing branch';
+      reuseExistingBranch = true;
       const res = await doAutoReplace(
         upgrade,
         'existing content',
-        parentBranch
+        reuseExistingBranch
       );
       expect(res).toBeNull();
     });
     it('rebases if the deps to update has changed', async () => {
       upgrade.baseDeps = extractPackageFile(sampleHtml).deps;
       upgrade.baseDeps[0].currentValue = '1.0.0';
-      parentBranch = 'some existing branch';
-      const res = await doAutoReplace(upgrade, sampleHtml, parentBranch);
+      reuseExistingBranch = true;
+      const res = await doAutoReplace(upgrade, sampleHtml, reuseExistingBranch);
       expect(res).toBeNull();
     });
     it('updates version only', async () => {
@@ -51,7 +51,7 @@ describe('workers/branch/auto-replace', () => {
       upgrade.newValue = '7.1.1';
       upgrade.newDigest = 'some-digest';
       upgrade.depIndex = 0;
-      const res = await doAutoReplace(upgrade, src, parentBranch);
+      const res = await doAutoReplace(upgrade, src, reuseExistingBranch);
       expect(res).toMatchSnapshot();
     });
     it('handles a double attempt', async () => {
@@ -64,7 +64,7 @@ describe('workers/branch/auto-replace', () => {
       upgrade.currentValue = '7.1.0';
       upgrade.newValue = '7.1.1';
       upgrade.depIndex = 1;
-      const res = await doAutoReplace(upgrade, src, parentBranch);
+      const res = await doAutoReplace(upgrade, src, reuseExistingBranch);
       expect(res).toMatchSnapshot();
     });
     it('handles already updated', async () => {
@@ -78,9 +78,13 @@ describe('workers/branch/auto-replace', () => {
       upgrade.newValue = '7.1.1';
       upgrade.depIndex = 0;
       upgrade.replaceString = script;
-      parentBranch = 'something';
+      reuseExistingBranch = true;
       const srcAlreadyUpdated = src.replace('7.1.0', '7.1.1');
-      const res = await doAutoReplace(upgrade, srcAlreadyUpdated, parentBranch);
+      const res = await doAutoReplace(
+        upgrade,
+        srcAlreadyUpdated,
+        reuseExistingBranch
+      );
       expect(res).toMatchSnapshot();
     });
     it('returns existing content if replaceString mismatch', async () => {
@@ -94,7 +98,11 @@ describe('workers/branch/auto-replace', () => {
       upgrade.newValue = '7.1.1';
       upgrade.depIndex = 0;
       upgrade.replaceString = script;
-      const res = await doAutoReplace(upgrade, 'wrong source', parentBranch);
+      const res = await doAutoReplace(
+        upgrade,
+        'wrong source',
+        reuseExistingBranch
+      );
       expect(res).toEqual('wrong source');
     });
     it('updates version and integrity', async () => {
@@ -111,7 +119,7 @@ describe('workers/branch/auto-replace', () => {
       upgrade.newDigest = 'sha256-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
       upgrade.depIndex = 0;
       upgrade.replaceString = script;
-      const res = await doAutoReplace(upgrade, src, parentBranch);
+      const res = await doAutoReplace(upgrade, src, reuseExistingBranch);
       expect(res).toMatchSnapshot();
     });
     it('updates with autoReplaceNewString', async () => {
@@ -130,7 +138,7 @@ describe('workers/branch/auto-replace', () => {
         'node:8.11.3-alpine@sha256:d743b4141b02fcfb8beb68f92b4cd164f60ee457bf2d053f36785bf86de16b0d';
       upgrade.autoReplaceStringTemplate =
         '{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}';
-      const res = await doAutoReplace(upgrade, dockerfile, parentBranch);
+      const res = await doAutoReplace(upgrade, dockerfile, reuseExistingBranch);
       expect(res).toMatchSnapshot();
     });
   });
diff --git a/lib/workers/branch/auto-replace.ts b/lib/workers/branch/auto-replace.ts
index b25b43fcf9..0cd88d02e3 100644
--- a/lib/workers/branch/auto-replace.ts
+++ b/lib/workers/branch/auto-replace.ts
@@ -103,7 +103,7 @@ export async function checkBranchDepsMatchBaseDeps(
 export async function doAutoReplace(
   upgrade: BranchUpgradeConfig,
   existingContent: string,
-  parentBranch: string | null
+  reuseExistingBranch: boolean
 ): Promise<string | null> {
   const {
     packageFile,
@@ -114,7 +114,7 @@ export async function doAutoReplace(
     newDigest,
     autoReplaceStringTemplate,
   } = upgrade;
-  if (parentBranch) {
+  if (reuseExistingBranch) {
     if (!(await checkBranchDepsMatchBaseDeps(upgrade, existingContent))) {
       logger.debug(
         { packageFile, depName },
diff --git a/lib/workers/branch/get-updated.spec.ts b/lib/workers/branch/get-updated.spec.ts
index 74b6b6308c..770269fe8b 100644
--- a/lib/workers/branch/get-updated.spec.ts
+++ b/lib/workers/branch/get-updated.spec.ts
@@ -46,7 +46,7 @@ describe('workers/branch/get-updated', () => {
       await expect(getUpdatedPackageFiles(config)).rejects.toThrow();
     });
     it('handles autoreplace branch needs update', async () => {
-      config.parentBranch = 'some branch';
+      config.reuseExistingBranch = true;
       config.upgrades.push({ manager: 'html', branchName: undefined });
       autoReplace.doAutoReplace.mockResolvedValueOnce(null);
       autoReplace.doAutoReplace.mockResolvedValueOnce('updated-file');
@@ -58,14 +58,14 @@ describe('workers/branch/get-updated', () => {
       expect(res).toMatchSnapshot();
     });
     it('handles null content', async () => {
-      config.parentBranch = 'some-branch';
+      config.reuseExistingBranch = true;
       config.upgrades.push({
         manager: 'npm',
       } as never);
       await expect(getUpdatedPackageFiles(config)).rejects.toThrow();
     });
     it('handles content change', async () => {
-      config.parentBranch = 'some-branch';
+      config.reuseExistingBranch = true;
       config.upgrades.push({
         manager: 'npm',
       } as never);
@@ -74,7 +74,7 @@ describe('workers/branch/get-updated', () => {
       expect(res).toMatchSnapshot();
     });
     it('handles lock files', async () => {
-      config.parentBranch = 'some-branch';
+      config.reuseExistingBranch = true;
       config.upgrades.push({
         manager: 'composer',
         branchName: undefined,
@@ -92,7 +92,6 @@ describe('workers/branch/get-updated', () => {
       expect(res).toMatchSnapshot();
     });
     it('handles lockFileMaintenance', async () => {
-      // config.parentBranch = 'some-branch';
       config.upgrades.push({
         manager: 'composer',
         updateType: 'lockFileMaintenance',
@@ -109,7 +108,6 @@ describe('workers/branch/get-updated', () => {
       expect(res).toMatchSnapshot();
     });
     it('handles lockFileMaintenance error', async () => {
-      // config.parentBranch = 'some-branch';
       config.upgrades.push({
         manager: 'composer',
         updateType: 'lockFileMaintenance',
@@ -126,7 +124,7 @@ describe('workers/branch/get-updated', () => {
       expect(res).toMatchSnapshot();
     });
     it('handles lock file errors', async () => {
-      config.parentBranch = 'some-branch';
+      config.reuseExistingBranch = true;
       config.upgrades.push({
         manager: 'composer',
         branchName: undefined,
diff --git a/lib/workers/branch/get-updated.ts b/lib/workers/branch/get-updated.ts
index e546418655..569dd61af9 100644
--- a/lib/workers/branch/get-updated.ts
+++ b/lib/workers/branch/get-updated.ts
@@ -10,7 +10,7 @@ import { doAutoReplace } from './auto-replace';
 
 export interface PackageFilesResult {
   artifactErrors: ArtifactError[];
-  parentBranch?: string;
+  reuseExistingBranch?: boolean;
   updatedPackageFiles: File[];
   updatedArtifacts: File[];
 }
@@ -19,9 +19,9 @@ export async function getUpdatedPackageFiles(
   config: BranchConfig
 ): Promise<PackageFilesResult> {
   logger.trace({ config });
-  const { branchName, parentBranch } = config;
+  const { branchName, reuseExistingBranch } = config;
   logger.debug(
-    { parentBranch, branchName },
+    { reuseExistingBranch, branchName },
     'manager.getUpdatedPackageFiles()'
   );
   const updatedFileContents: Record<string, string> = {};
@@ -38,27 +38,30 @@ export async function getUpdatedPackageFiles(
       lockFileMaintenanceFiles.push(packageFile);
     } else {
       let existingContent = updatedFileContents[packageFile];
-      // istanbul ignore if
-      if (existingContent) {
-        logger.debug({ packageFile }, 'Reusing updated contents');
-      } else {
-        logger.debug(`platform.getFile(${packageFile}, ${parentBranch})`);
-        existingContent = await platform.getFile(packageFile, parentBranch);
+      if (!existingContent) {
+        existingContent = await platform.getFile(
+          packageFile,
+          reuseExistingBranch ? config.branchName : config.baseBranch
+        );
       }
       // istanbul ignore if
-      if (config.parentBranch && !existingContent) {
+      if (config.reuseExistingBranch && !existingContent) {
         logger.debug(
           { packageFile, depName },
           'Rebasing branch after file not found'
         );
         return getUpdatedPackageFiles({
           ...config,
-          parentBranch: undefined,
+          reuseExistingBranch: false,
         });
       }
       const updateDependency = get(manager, 'updateDependency');
       if (!updateDependency) {
-        const res = await doAutoReplace(upgrade, existingContent, parentBranch);
+        const res = await doAutoReplace(
+          upgrade,
+          existingContent,
+          reuseExistingBranch
+        );
         if (res) {
           if (res === existingContent) {
             logger.debug({ packageFile, depName }, 'No content changed');
@@ -67,10 +70,10 @@ export async function getUpdatedPackageFiles(
             updatedFileContents[packageFile] = res;
           }
           continue; // eslint-disable-line no-continue
-        } else if (parentBranch) {
+        } else if (reuseExistingBranch) {
           return getUpdatedPackageFiles({
             ...config,
-            parentBranch: undefined,
+            reuseExistingBranch: false,
           });
         }
         logger.error({ packageFile, depName }, 'Could not autoReplace');
@@ -81,14 +84,14 @@ export async function getUpdatedPackageFiles(
         upgrade,
       });
       if (!newContent) {
-        if (config.parentBranch) {
+        if (config.reuseExistingBranch) {
           logger.debug(
             { packageFile, depName },
             'Rebasing branch after error updating content'
           );
           return getUpdatedPackageFiles({
             ...config,
-            parentBranch: undefined,
+            reuseExistingBranch: false,
           });
         }
         logger.debug(
@@ -98,7 +101,7 @@ export async function getUpdatedPackageFiles(
         throw new Error(WORKER_FILE_UPDATE_FAILED);
       }
       if (newContent !== existingContent) {
-        if (config.parentBranch) {
+        if (config.reuseExistingBranch) {
           // This ensure it's always 1 commit from the bot
           logger.debug(
             { packageFile, depName },
@@ -106,7 +109,7 @@ export async function getUpdatedPackageFiles(
           );
           return getUpdatedPackageFiles({
             ...config,
-            parentBranch: undefined,
+            reuseExistingBranch: false,
           });
         }
         logger.debug({ packageFile, depName }, 'Updating packageFile content');
@@ -149,7 +152,7 @@ export async function getUpdatedPackageFiles(
       }
     }
   }
-  if (!config.parentBranch) {
+  if (!config.reuseExistingBranch) {
     // Only perform lock file maintenance if it's a fresh commit
     for (const packageFile of lockFileMaintenanceFiles) {
       const manager = packageFileManagers[packageFile];
@@ -157,7 +160,10 @@ export async function getUpdatedPackageFiles(
       if (updateArtifacts) {
         const packageFileContents =
           updatedFileContents[packageFile] ||
-          (await platform.getFile(packageFile, config.parentBranch));
+          (await platform.getFile(
+            packageFile,
+            config.reuseExistingBranch ? config.branchName : config.baseBranch
+          ));
         const results = await updateArtifacts({
           packageFileName: packageFile,
           updatedDeps: [],
@@ -178,7 +184,7 @@ export async function getUpdatedPackageFiles(
     }
   }
   return {
-    parentBranch: config.parentBranch, // Need to overwrite original config
+    reuseExistingBranch: config.reuseExistingBranch, // Need to overwrite original config
     updatedPackageFiles,
     updatedArtifacts,
     artifactErrors,
diff --git a/lib/workers/branch/index.spec.ts b/lib/workers/branch/index.spec.ts
index 2ddc134716..8c73310cef 100644
--- a/lib/workers/branch/index.spec.ts
+++ b/lib/workers/branch/index.spec.ts
@@ -19,7 +19,7 @@ import * as _automerge from './automerge';
 import * as _checkExisting from './check-existing';
 import * as _commit from './commit';
 import * as _getUpdated from './get-updated';
-import * as _parent from './parent';
+import * as _reuse from './reuse';
 import * as _schedule from './schedule';
 import * as _statusChecks from './status-checks';
 import * as branchWorker from '.';
@@ -27,7 +27,7 @@ import * as branchWorker from '.';
 jest.mock('./get-updated');
 jest.mock('./schedule');
 jest.mock('./check-existing');
-jest.mock('./parent');
+jest.mock('./reuse');
 jest.mock('../../manager/npm/post-update');
 jest.mock('./status-checks');
 jest.mock('./automerge');
@@ -39,7 +39,7 @@ jest.mock('fs-extra');
 const getUpdated = mocked(_getUpdated);
 const schedule = mocked(_schedule);
 const checkExisting = mocked(_checkExisting);
-const parent = mocked(_parent);
+const reuse = mocked(_reuse);
 const npmPostExtract = mocked(_npmPostExtract);
 const statusChecks = mocked(_statusChecks);
 const automerge = mocked(_automerge);
@@ -127,7 +127,7 @@ describe('workers/branch', () => {
         state: PR_STATE_CLOSED,
       } as never);
       await branchWorker.processBranch(config);
-      expect(parent.getParentBranch).toHaveBeenCalledTimes(0);
+      expect(reuse.shouldReuseExistingBranch).toHaveBeenCalledTimes(0);
     });
     it('skips branch if closed digest PR found', async () => {
       schedule.isScheduledNow.mockReturnValueOnce(false);
@@ -138,7 +138,7 @@ describe('workers/branch', () => {
         state: PR_STATE_CLOSED,
       });
       await branchWorker.processBranch(config);
-      expect(parent.getParentBranch).toHaveBeenCalledTimes(0);
+      expect(reuse.shouldReuseExistingBranch).toHaveBeenCalledTimes(0);
     });
     it('skips branch if closed minor PR found', async () => {
       schedule.isScheduledNow.mockReturnValueOnce(false);
@@ -148,7 +148,7 @@ describe('workers/branch', () => {
         state: PR_STATE_CLOSED,
       });
       await branchWorker.processBranch(config);
-      expect(parent.getParentBranch).toHaveBeenCalledTimes(0);
+      expect(reuse.shouldReuseExistingBranch).toHaveBeenCalledTimes(0);
     });
     it('skips branch if merged PR found', async () => {
       schedule.isScheduledNow.mockReturnValueOnce(false);
@@ -158,7 +158,7 @@ describe('workers/branch', () => {
         state: PR_STATE_MERGED,
       });
       await branchWorker.processBranch(config);
-      expect(parent.getParentBranch).toHaveBeenCalledTimes(0);
+      expect(reuse.shouldReuseExistingBranch).toHaveBeenCalledTimes(0);
     });
     it('throws error if closed PR found', async () => {
       schedule.isScheduledNow.mockReturnValueOnce(false);
@@ -546,7 +546,7 @@ describe('workers/branch', () => {
           ...config,
           dryRun: true,
           updateType: 'lockFileMaintenance',
-          parentBranch: undefined,
+          reuseExistingBranch: false,
           updatedArtifacts: [{ name: '|delete|', contents: 'dummy' }],
         })
       ).toEqual('done');
@@ -607,7 +607,7 @@ describe('workers/branch', () => {
         await branchWorker.processBranch({
           ...config,
           updateType: 'lockFileMaintenance',
-          parentBranch: undefined,
+          reuseExistingBranch: false,
           updatedArtifacts: [{ name: '|delete|', contents: 'dummy' }],
         })
       ).toEqual('done');
diff --git a/lib/workers/branch/index.ts b/lib/workers/branch/index.ts
index cdf2e01312..c92e6f50ba 100644
--- a/lib/workers/branch/index.ts
+++ b/lib/workers/branch/index.ts
@@ -35,7 +35,7 @@ import { tryBranchAutomerge } from './automerge';
 import { prAlreadyExisted } from './check-existing';
 import { commitFilesToBranch } from './commit';
 import { getUpdatedPackageFiles } from './get-updated';
-import { getParentBranch } from './parent';
+import { shouldReuseExistingBranch } from './reuse';
 import { isScheduledNow } from './schedule';
 import { setStability, setUnpublishable } from './status-checks';
 
@@ -281,11 +281,11 @@ export async function processBranch(
     // istanbul ignore if
     if (masterIssueCheck === 'rebase' || config.masterIssueRebaseAllOpen) {
       logger.debug('Manual rebase requested via master issue');
-      delete config.parentBranch;
+      config.reuseExistingBranch = false;
     } else {
-      Object.assign(config, await getParentBranch(config));
+      Object.assign(config, await shouldReuseExistingBranch(config));
     }
-    logger.debug(`Using parentBranch: ${config.parentBranch}`);
+    logger.debug(`Using reuseExistingBranch: ${config.reuseExistingBranch}`);
     const res = await getUpdatedPackageFiles(config);
     // istanbul ignore if
     if (res.artifactErrors && config.artifactErrors) {
diff --git a/lib/workers/branch/lock-files/index.spec.ts b/lib/workers/branch/lock-files/index.spec.ts
index 5ee5f65fe4..79be0de9d3 100644
--- a/lib/workers/branch/lock-files/index.spec.ts
+++ b/lib/workers/branch/lock-files/index.spec.ts
@@ -333,7 +333,7 @@ describe('manager/npm/post-update', () => {
     });
     it('returns no error and empty lockfiles if lock file maintenance exists', async () => {
       config.updateType = 'lockFileMaintenance';
-      config.parentBranch = 'renovate/lock-file-maintenance';
+      config.reuseExistingBranch = true;
       platform.branchExists.mockResolvedValueOnce(true);
       const res = await getAdditionalFiles(config, { npm: [{}] });
       expect(res).toMatchSnapshot();
diff --git a/lib/workers/branch/parent.spec.ts b/lib/workers/branch/reuse.spec.ts
similarity index 73%
rename from lib/workers/branch/parent.spec.ts
rename to lib/workers/branch/reuse.spec.ts
index a7ac9344af..27b4151081 100644
--- a/lib/workers/branch/parent.spec.ts
+++ b/lib/workers/branch/reuse.spec.ts
@@ -2,7 +2,7 @@ import { platform } from '../../../test/util';
 import { RenovateConfig } from '../../config';
 import { PR_STATE_OPEN } from '../../constants/pull-requests';
 import { Pr } from '../../platform';
-import { getParentBranch } from './parent';
+import { shouldReuseExistingBranch } from './reuse';
 
 describe('workers/branch/parent', () => {
   describe('getParentBranch(config)', () => {
@@ -24,14 +24,14 @@ describe('workers/branch/parent', () => {
     });
     it('returns undefined if branch does not exist', async () => {
       platform.branchExists.mockResolvedValueOnce(false);
-      const res = await getParentBranch(config);
-      expect(res.parentBranch).toBeUndefined();
+      const res = await shouldReuseExistingBranch(config);
+      expect(res.reuseExistingBranch).toBe(false);
     });
     it('returns branchName if no PR', async () => {
       platform.branchExists.mockResolvedValueOnce(true);
       platform.getBranchPr.mockReturnValue(null);
-      const res = await getParentBranch(config);
-      expect(res.parentBranch).toBe(config.branchName);
+      const res = await shouldReuseExistingBranch(config);
+      expect(res.reuseExistingBranch).toBe(true);
     });
     it('returns branchName if does not need rebaseing', async () => {
       platform.branchExists.mockResolvedValueOnce(true);
@@ -39,8 +39,8 @@ describe('workers/branch/parent', () => {
         ...pr,
         isConflicted: false,
       });
-      const res = await getParentBranch(config);
-      expect(res.parentBranch).toBe(config.branchName);
+      const res = await shouldReuseExistingBranch(config);
+      expect(res.reuseExistingBranch).toBe(true);
     });
     it('returns branchName if unmergeable and cannot rebase', async () => {
       platform.branchExists.mockResolvedValueOnce(true);
@@ -49,8 +49,8 @@ describe('workers/branch/parent', () => {
         isConflicted: true,
         isModified: true,
       });
-      const res = await getParentBranch(config);
-      expect(res.parentBranch).toBe(config.branchName);
+      const res = await shouldReuseExistingBranch(config);
+      expect(res.reuseExistingBranch).toBe(true);
     });
     it('returns branchName if unmergeable and can rebase, but rebaseWhen is never', async () => {
       config.rebaseWhen = 'never';
@@ -60,8 +60,8 @@ describe('workers/branch/parent', () => {
         isConflicted: true,
         isModified: false,
       });
-      const res = await getParentBranch(config);
-      expect(res.parentBranch).toBe(config.branchName);
+      const res = await shouldReuseExistingBranch(config);
+      expect(res.reuseExistingBranch).toBe(true);
     });
     it('returns undefined if PR title rebase!', async () => {
       platform.branchExists.mockResolvedValueOnce(true);
@@ -69,8 +69,8 @@ describe('workers/branch/parent', () => {
         ...pr,
         title: 'rebase!Update foo to v4',
       });
-      const res = await getParentBranch(config);
-      expect(res.parentBranch).toBeUndefined();
+      const res = await shouldReuseExistingBranch(config);
+      expect(res.reuseExistingBranch).toBe(false);
     });
     it('returns undefined if PR body check rebase', async () => {
       platform.branchExists.mockResolvedValueOnce(true);
@@ -79,8 +79,8 @@ describe('workers/branch/parent', () => {
         title: 'Update foo to v4',
         body: 'blah\nblah\n- [x] <!-- rebase-check -->foo\n',
       });
-      const res = await getParentBranch(config);
-      expect(res.parentBranch).toBeUndefined();
+      const res = await shouldReuseExistingBranch(config);
+      expect(res.reuseExistingBranch).toBe(false);
     });
     it('returns undefined if manual rebase by label', async () => {
       platform.branchExists.mockResolvedValueOnce(true);
@@ -89,8 +89,8 @@ describe('workers/branch/parent', () => {
         isModified: true,
         labels: ['rebase'],
       });
-      const res = await getParentBranch(config);
-      expect(res.parentBranch).toBeUndefined();
+      const res = await shouldReuseExistingBranch(config);
+      expect(res.reuseExistingBranch).toBe(false);
     });
     it('returns undefined if unmergeable and can rebase', async () => {
       platform.branchExists.mockResolvedValueOnce(true);
@@ -99,23 +99,23 @@ describe('workers/branch/parent', () => {
         isConflicted: true,
         isModified: false,
       });
-      const res = await getParentBranch(config);
-      expect(res.parentBranch).toBeUndefined();
+      const res = await shouldReuseExistingBranch(config);
+      expect(res.reuseExistingBranch).toBe(false);
     });
     it('returns branchName if automerge branch and not stale', async () => {
       config.automerge = true;
       config.automergeType = 'branch';
       platform.branchExists.mockResolvedValueOnce(true);
-      const res = await getParentBranch(config);
-      expect(res.parentBranch).toBe(config.branchName);
+      const res = await shouldReuseExistingBranch(config);
+      expect(res.reuseExistingBranch).toBe(true);
     });
     it('returns undefined if automerge branch and stale', async () => {
       config.automerge = true;
       config.automergeType = 'branch';
       platform.branchExists.mockResolvedValueOnce(true);
       platform.isBranchStale.mockResolvedValueOnce(true);
-      const res = await getParentBranch(config);
-      expect(res.parentBranch).toBeUndefined();
+      const res = await shouldReuseExistingBranch(config);
+      expect(res.reuseExistingBranch).toBe(false);
     });
     it('returns branch if rebaseWhen=behind-base-branch but cannot rebase', async () => {
       config.rebaseWhen = 'behind-base-branch';
@@ -126,8 +126,8 @@ describe('workers/branch/parent', () => {
         isConflicted: true,
         isModified: true,
       });
-      const res = await getParentBranch(config);
-      expect(res.parentBranch).not.toBeUndefined();
+      const res = await shouldReuseExistingBranch(config);
+      expect(res.reuseExistingBranch).toBe(true);
     });
   });
 });
diff --git a/lib/workers/branch/parent.ts b/lib/workers/branch/reuse.ts
similarity index 77%
rename from lib/workers/branch/parent.ts
rename to lib/workers/branch/reuse.ts
index 51834802fd..63c65f9995 100644
--- a/lib/workers/branch/parent.ts
+++ b/lib/workers/branch/reuse.ts
@@ -2,9 +2,12 @@ import { RenovateConfig } from '../../config';
 import { logger } from '../../logger';
 import { platform } from '../../platform';
 
-type ParentBranch = { parentBranch: string | undefined; isModified?: boolean };
+type ParentBranch = {
+  reuseExistingBranch: boolean;
+  isModified?: boolean;
+};
 
-export async function getParentBranch(
+export async function shouldReuseExistingBranch(
   config: RenovateConfig
 ): Promise<ParentBranch> {
   const { branchName } = config;
@@ -12,7 +15,7 @@ export async function getParentBranch(
   const branchExists = await platform.branchExists(branchName);
   if (!branchExists) {
     logger.debug(`Branch needs creating`);
-    return { parentBranch: undefined };
+    return { reuseExistingBranch: false };
   }
   logger.debug(`Branch already exists`);
 
@@ -22,11 +25,11 @@ export async function getParentBranch(
   if (pr) {
     if (pr.title && pr.title.startsWith('rebase!')) {
       logger.debug('Manual rebase requested via PR title for #' + pr.number);
-      return { parentBranch: undefined };
+      return { reuseExistingBranch: false };
     }
     if (pr.body && pr.body.includes(`- [x] <!-- rebase-check -->`)) {
       logger.debug('Manual rebase requested via PR checkbox for #' + pr.number);
-      return { parentBranch: undefined };
+      return { reuseExistingBranch: false };
     }
     if (pr.labels && pr.labels.includes(config.rebaseLabel)) {
       logger.debug('Manual rebase requested via PR labels for #' + pr.number);
@@ -38,7 +41,7 @@ export async function getParentBranch(
       } else {
         await platform.deleteLabel(pr.number, config.rebaseLabel);
       }
-      return { parentBranch: undefined };
+      return { reuseExistingBranch: false };
     }
   }
 
@@ -52,11 +55,11 @@ export async function getParentBranch(
       logger.debug(`Branch is stale and needs rebasing`);
       // We can rebase the branch only if no PR or PR can be rebased
       if (!pr || !pr.isModified) {
-        return { parentBranch: undefined };
+        return { reuseExistingBranch: false };
       }
       // TODO: Warn here so that it appears in PR body
       logger.debug('Cannot rebase branch');
-      return { parentBranch: branchName, isModified: true };
+      return { reuseExistingBranch: true, isModified: true };
     }
   }
 
@@ -68,15 +71,15 @@ export async function getParentBranch(
       logger.debug(`Branch is not mergeable and needs rebasing`);
       if (config.rebaseWhen === 'never') {
         logger.debug('Rebasing disabled by config');
-        return { parentBranch: branchName, isModified: false };
+        return { reuseExistingBranch: true, isModified: false };
       }
-      // Setting parentBranch back to undefined means that we'll use the default branch
-      return { parentBranch: undefined };
+      // Setting reuseExistingBranch back to undefined means that we'll use the default branch
+      return { reuseExistingBranch: false };
     }
     // Don't do anything different, but warn
     // TODO: Add warning to PR
     logger.debug(`Branch is not mergeable but can't be rebased`);
   }
   logger.debug(`Branch does not need rebasing`);
-  return { parentBranch: branchName, isModified: false };
+  return { reuseExistingBranch: true, isModified: false };
 }
diff --git a/lib/workers/common.ts b/lib/workers/common.ts
index d1c95cbbad..b38db03d9c 100644
--- a/lib/workers/common.ts
+++ b/lib/workers/common.ts
@@ -42,7 +42,7 @@ export interface BranchUpgradeConfig
   manager?: string;
   packageFile?: string;
 
-  parentBranch?: string;
+  reuseExistingBranch?: boolean;
   prBanner?: string;
   prBodyNotes?: string[];
   prBodyTemplate?: string;
-- 
GitLab