From a36073f141c3518bb138d88f7c8cbaa221328d32 Mon Sep 17 00:00:00 2001
From: Frankly George <54015-franklygeorge@users.noreply.gitgud.io>
Date: Wed, 10 Apr 2024 17:56:46 +0000
Subject: [PATCH] Fix bug in changed line detection

---
 devTools/scripts/detectChanges.js | 38 +++++++++++++++++--------------
 1 file changed, 21 insertions(+), 17 deletions(-)

diff --git a/devTools/scripts/detectChanges.js b/devTools/scripts/detectChanges.js
index 58d660e6247..ec72609014c 100644
--- a/devTools/scripts/detectChanges.js
+++ b/devTools/scripts/detectChanges.js
@@ -168,23 +168,27 @@ class ChangeParser {
 			} else {
 				const command = `git diff -U${this.countFileLines(file)} ${this.mergeCommit} -- ${file}`;
 				/** @type {Array<string>} */
-				let result = execSync(command).toString().trim().split('\n');
-
-				// remove first two lines
-				result = result.slice(2);
-				// remove all lines starting with ---, +++, or @@
-				result = result.filter(line => !line.startsWith("---") && !line.startsWith("+++") && !line.startsWith("@@"));
-				// remove all lines starting with -
-				result = result.filter(line => !line.startsWith("-"));
-				let lineNo = 0;
-				// for each line
-				result.forEach(line => {
-					lineNo += 1;
-					// if line starts with + add line number to changed lines
-					if (line.startsWith("+")) {
-						changed[file].push(lineNo);
-					}
-				});
+				try {
+					let result = execSync(command).toString().trim().split('\n');
+
+					// remove first two lines
+					result = result.slice(2);
+					// remove all lines starting with ---, +++, or @@
+					result = result.filter(line => !line.startsWith("---") && !line.startsWith("+++") && !line.startsWith("@@"));
+					// remove all lines starting with -
+					result = result.filter(line => !line.startsWith("-"));
+					let lineNo = 0;
+					// for each line
+					result.forEach(line => {
+						lineNo += 1;
+						// if line starts with + add line number to changed lines
+						if (line.startsWith("+")) {
+							changed[file].push(lineNo);
+						}
+					});
+				} catch {
+					// git fails with a `Circular *1` error sometimes on merge commits
+				}
 			}
 		}
 
-- 
GitLab