From 805ae952e6b6e70457007a3707f6cb3d9aad5443 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Tue, 14 May 2019 13:11:06 +0200
Subject: [PATCH] fix: rebase if package file not found in existing branch

---
 lib/workers/branch/get-updated.js       | 8 ++++++++
 test/workers/branch/get-updated.spec.js | 1 +
 2 files changed, 9 insertions(+)

diff --git a/lib/workers/branch/get-updated.js b/lib/workers/branch/get-updated.js
index 62e396bedf..32608026e5 100644
--- a/lib/workers/branch/get-updated.js
+++ b/lib/workers/branch/get-updated.js
@@ -22,6 +22,14 @@ async function getUpdatedPackageFiles(config) {
       const existingContent =
         updatedFileContents[packageFile] ||
         (await platform.getFile(packageFile, config.parentBranch));
+      // istanbul ignore if
+      if (config.parentBranch && !existingContent) {
+        logger.info('Rebasing branch after file not found');
+        return getUpdatedPackageFiles({
+          ...config,
+          parentBranch: undefined,
+        });
+      }
       let newContent = existingContent;
       const updateDependency = get(manager, 'updateDependency');
       newContent = await updateDependency(existingContent, upgrade);
diff --git a/test/workers/branch/get-updated.spec.js b/test/workers/branch/get-updated.spec.js
index ee4a5f4201..168a22cc61 100644
--- a/test/workers/branch/get-updated.spec.js
+++ b/test/workers/branch/get-updated.spec.js
@@ -16,6 +16,7 @@ describe('workers/branch/get-updated', () => {
       composer.updateDependency = jest.fn();
       composer.getArtifacts = jest.fn();
       npm.updateDependency = jest.fn();
+      platform.getFile.mockReturnValueOnce('existing content');
     });
     it('handles empty', async () => {
       const res = await getUpdatedPackageFiles(config);
-- 
GitLab