From 2ce8937705696ba497788e3a47f04edd23097d0f Mon Sep 17 00:00:00 2001
From: JediKev <kevin@enhancesoft.com>
Date: Thu, 26 Apr 2018 16:30:00 -0500
Subject: [PATCH] tests: Git Conflict Markers

This adds a test for Git Conflict Markers to prevent committing unfinished
merge conflicts. This will find any `<<<<<<< HEAD`/`>>>>>>>` markers
and will fail out with the line of code, filename and line number.
---
 setup/test/tests/test.git-conflicts.php | 27 +++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
 create mode 100644 setup/test/tests/test.git-conflicts.php

diff --git a/setup/test/tests/test.git-conflicts.php b/setup/test/tests/test.git-conflicts.php
new file mode 100644
index 000000000..5aa27bfb9
--- /dev/null
+++ b/setup/test/tests/test.git-conflicts.php
@@ -0,0 +1,27 @@
+<?php
+require_once "class.test.php";
+
+class GitConflicts extends Test {
+    var $name = "Git Conflicts Checks";
+
+    function testFindGitConflicts() {
+        $regex = '/^[\t ]*?<{3,} ?HEAD[\t ]*?|^[\t ]*?>{3,}[\t ]*?/m';
+        foreach ($this->getAllScripts('*') as $s) {
+            $matches = array();
+            $content = file_get_contents($s);
+            if (preg_match_all($regex,
+                    $content, $matches,
+                    PREG_OFFSET_CAPTURE) > 0) {
+                foreach ($matches[0] as $match) {
+                    $this->fail(
+                        $s,
+                        $this->line_number_for_offset($content, $match[1]),
+                        trim($match[0]));
+                }
+            }
+            else $this->pass();
+        }
+    }
+}
+return 'GitConflicts';
+?>
-- 
GitLab