From a2a6ac94ccc358d19f19b5d16a291a79e16ff7c1 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Sat, 15 May 2021 07:57:48 +0200
Subject: [PATCH] fix(git): defensive fileList check

---
 lib/util/git/index.ts | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/lib/util/git/index.ts b/lib/util/git/index.ts
index 5facb30fd6..b141f09450 100644
--- a/lib/util/git/index.ts
+++ b/lib/util/git/index.ts
@@ -433,7 +433,19 @@ export async function getFileList(): Promise<string[]> {
   await syncGit();
   const branch = config.currentBranch;
   const submodules = await getSubmodules();
-  const files: string = await git.raw(['ls-tree', '-r', branch]);
+  let files: string;
+  try {
+    files = await git.raw(['ls-tree', '-r', branch]);
+  } catch (err) /* istanbul ignore next */ {
+    if (err.message?.includes('fatal: Not a valid object name')) {
+      logger.debug(
+        { err },
+        'Branch not found when checking branch list - aborting'
+      );
+      throw new Error(REPOSITORY_CHANGED);
+    }
+    throw err;
+  }
   // istanbul ignore if
   if (!files) {
     return [];
-- 
GitLab