Skip to content
Snippets Groups Projects
Commit 2ce89377 authored by JediKev's avatar JediKev
Browse files

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.
parent 24dbd3b3
No related branches found
No related tags found
No related merge requests found
<?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';
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment