summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordbeam@chromium.org <dbeam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-20 03:45:03 +0000
committerdbeam@chromium.org <dbeam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-20 03:45:03 +0000
commit70ca7775fe7edbe3973e3507c6ca00d26e4df5dc (patch)
treedc03834235c802d64b9a0beb4d9e0373f8f402ad
parent2ba8d10b3ee068b2c29550a7976b593abc0a090a (diff)
downloadchromium_src-70ca7775fe7edbe3973e3507c6ca00d26e4df5dc.zip
chromium_src-70ca7775fe7edbe3973e3507c6ca00d26e4df5dc.tar.gz
chromium_src-70ca7775fe7edbe3973e3507c6ca00d26e4df5dc.tar.bz2
Adds a presubmit that looks for version control conflicts.
R=maruel@chromium.org,thakis@chromium.org BUG=None Review URL: https://chromiumcodereview.appspot.com/11417044 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@168715 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--PRESUBMIT.py23
-rwxr-xr-xPRESUBMIT_test.py19
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()