diff options
-rw-r--r-- | PRESUBMIT.py | 23 | ||||
-rwxr-xr-x | PRESUBMIT_test.py | 19 |
2 files changed, 42 insertions, 0 deletions
diff --git a/PRESUBMIT.py b/PRESUBMIT.py index 2c6df72..7d93fa2 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -635,6 +635,28 @@ def _CheckIncludeOrder(input_api, output_api): return results +def _CheckForVersionControlConflictsInFile(input_api, f): + pattern = input_api.re.compile('^(?:<<<<<<<|>>>>>>>) |^=======$') + errors = [] + for line_num, line in f.ChangedContents(): + if pattern.match(line): + errors.append(' %s:%d %s' % (f.LocalPath(), line_num, line)) + return errors + + +def _CheckForVersionControlConflicts(input_api, output_api): + """Usually this is not intentional and will cause a compile failure.""" + errors = [] + for f in input_api.AffectedFiles(): + errors.extend(_CheckForVersionControlConflictsInFile(input_api, f)) + + results = [] + if errors: + results.append(output_api.PresubmitError( + 'Version control conflict markers found, please resolve.', errors)) + return results + + def _CommonChecks(input_api, output_api): """Checks common to both upload and commit.""" results = [] @@ -654,6 +676,7 @@ def _CommonChecks(input_api, output_api): results.extend(_CheckFilePermissions(input_api, output_api)) results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api)) results.extend(_CheckIncludeOrder(input_api, output_api)) + results.extend(_CheckForVersionControlConflicts(input_api, output_api)) if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): results.extend(input_api.canned_checks.RunUnitTestsInDirectory( diff --git a/PRESUBMIT_test.py b/PRESUBMIT_test.py index 4133458..80c1756 100755 --- a/PRESUBMIT_test.py +++ b/PRESUBMIT_test.py @@ -20,6 +20,10 @@ class MockFile(object): def __init__(self, local_path, new_contents): self._local_path = local_path self._new_contents = new_contents + self._changed_contents = [(i + 1, l) for i, l in enumerate(new_contents)] + + def ChangedContents(self): + return self._changed_contents def NewContents(self): return self._new_contents @@ -172,5 +176,20 @@ class IncludeOrderTest(unittest.TestCase): self.assertEqual(0, len(warnings)) +class VersionControlerConflictsTest(unittest.TestCase): + def testTypicalConflict(self): + lines = ['<<<<<<< HEAD', + ' base::ScopedTempDir temp_dir_;', + '=======', + ' ScopedTempDir temp_dir_;', + '>>>>>>> master'] + errors = PRESUBMIT._CheckForVersionControlConflictsInFile( + MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) + self.assertEqual(3, len(errors)) + self.assertTrue('1' in errors[0]) + self.assertTrue('3' in errors[1]) + self.assertTrue('5' in errors[2]) + + if __name__ == '__main__': unittest.main() |